load event not firing on svg with svgweb

眉间皱痕 提交于 2019-12-13 04:44:41

问题


I try to do some stuff after a SVG (referenced by an <object>:)

<!--[if !IE]>-->
<object data="file.svg" type="image/svg+xml" id="image-1" width="760" height="730" > <!--<![endif]-->
<!--[if lt IE 9]>
<object src="file.svg" classid="image/svg+xml" width="200" height="200" id="image-1" width="760" height="730"> <![endif]-->
<!--[if gte IE 9]>
<object data="file.svg" type="image/svg+xml" id="image-1" width="760" height="730">  
<![endif]-->
</object>

is loaded:

a = document.getElementById("image-1");
a.addEventListener("load",function(){
   //some stuff
},false);

This works fine in browser with native SVG support. Yet when the SVG is served with svgweb's flash support, I can't get a load event fired. Did I mess something up or this to be expected?

What can I do to fire an event when the flash fallback is ready? I need this to dynamically hide/show <path>s.


回答1:


Have you tried listening for the 'SVGLoad' event instead?

For how, see the user manual for SVGWeb.




回答2:


I've had trouble getting SVGWeb load events to fire consistently in different browsers with embedded SVG files. I've found this method to work everywhere and with jQuery:

At the END of your SVG file before the </svg> tag:

<script type="text/javascript"><![CDATA[
    window.parent.SVGInit();
]]></script>

Then in your HTML file ABOVE the SVG embed:

<script>
    function SVGInit() {
        $(document).ready(function(){
            // SVG is loaded and ready.
        });             
    }
</script>



回答3:


Which version of svgWeb are you using? Try updating to Lurker Above. Previous versions might override jquery's load handler. Also, try using this syntax :

mysvg.load = mysvg.onsvgload = function(){
    //Handler
}


来源:https://stackoverflow.com/questions/11377473/load-event-not-firing-on-svg-with-svgweb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!