Mathias
Mathias

Reputation: 334

load event not firing on svg with svgweb

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.

Upvotes: 0

Views: 1468

Answers (3)

dsdev
dsdev

Reputation: 1124

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>

Upvotes: 1

Armel Larcier
Armel Larcier

Reputation: 16027

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
}

Upvotes: 0

Erik Dahlstr&#246;m
Erik Dahlstr&#246;m

Reputation: 60966

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

For how, see the user manual for SVGWeb.

Upvotes: 1

Related Questions