最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

dom - Run Javascript function when object content has been loaded - Stack Overflow

programmeradmin9浏览0评论

How do I run a Javascript function when the content of an <object> has been loaded? The DOMContentLoaded event fires before that, and things that rely on it like JQuery's $() likewise.

Compare this to this. The first example fails because the function is executed when the external SVG hasn't been loaded. The second example polls for the elements it wants to change and only then executes the relevant code, and succeeds.

Polling works in practice, but is there a better solution for this? Ideally there would be an event fired that I can use.

How do I run a Javascript function when the content of an <object> has been loaded? The DOMContentLoaded event fires before that, and things that rely on it like JQuery's $() likewise.

Compare this to this. The first example fails because the function is executed when the external SVG hasn't been loaded. The second example polls for the elements it wants to change and only then executes the relevant code, and succeeds.

Polling works in practice, but is there a better solution for this? Ideally there would be an event fired that I can use.

Share Improve this question edited Jul 22, 2022 at 22:00 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Jun 27, 2013 at 15:42 Lars KotthoffLars Kotthoff 109k16 gold badges210 silver badges208 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 3

Does using the onload DomEvent work?

<object onload="changeColor()" data="circles.svg" type="image/svg+xml" id="circles"></object>

see my it here

You should use onload/ready event of jquery - http://api.jquery./ready/

$('#circles').ready(function(){
    changeColor();
});`
发布评论

评论列表(0)

  1. 暂无评论