在加载对象内容时运行Javascript函数 [英] Run Javascript function when object content has been loaded
问题描述
当加载了< object>
的内容时,如何运行Javascript函数? c $ c> DOMContentLoaded 事件在此之前触发,而依赖它的东西就像JQuery的 $()
同样。
将此与这个。第一个示例失败,因为在外部SVG尚未加载时执行该功能。第二个例子会轮询其想要更改的元素,然后执行相关代码,并成功。
投票工作在实践中,但是是否有更好的解决方案?理想的情况是会发生一个可以使用的事件。
使用onload DomEvent工作吗?
< object onload =changeColor()data =circles.svgtype =image / svg + xml ID = 圆圈 >< /对象>
看到我的 here
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.
Does using the onload DomEvent work?
<object onload="changeColor()" data="circles.svg" type="image/svg+xml" id="circles"></object>
see my it here
这篇关于在加载对象内容时运行Javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!