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

How do I run a Javascript function when the content of an <object> has been loaded? The DOMConten

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();
});`

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744124438a4559551.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信