views:

18

answers:

2

Hi

So I've got an XHTML page with a script - not inline

> <script type="text/javascript"
> src="../global/js/scripts.js"></script>

and an embedded (I tried embed and object, same behavior) SVG document with a onload="CheckIfLoaded(evt)" attribute.

The problem is firefox doesn't call the CheckIfLoaded() function in scripts.js. Firebug gives me "CheckIfLoaded() is not defined" with no reference to any line numbers. I can't find any information regarding the scope of javascript functions with respect to embedded content. Curiously, it works fine in IE.

I could of course add a reference to the script into the SVG file as well but I believe that will result in the client downloading the scripts file twice and in addition I have 1000+ svg files and I'd really rather not add one line to all of them, although I suppose I could write a batch file or whatever if I have to.

Any one know more about this?

Thanks, Nick

A: 

Are you sure that the script is getting loaded? Are there errors in the error console? If you put an alert() in the script, do you see it? (Before or after an alert() that you put in the onload handler?)

David Baron
Yes, I'm sure the script is loaded - I'm getting no other errors and I can hit breakpoints within other functions in the script.
Nick
A: 

Do you have the onload on the svg element or on the object/embed tag?

Sounds like you want to call functions in the referencing ("parent") document, see examples here.

Erik Dahlström
My onload is in the svg element.
Nick
Awesome. onload="top.CheckIfLoaded(evt)" works. Thanks Erik! Why is this stuff so difficult to find?
Nick
If you have several layers of embedding (e.g iframes within iframes) you may have to use 'parent.CheckIfLoaded()', 'top' gives you the root Window object, 'parent' gives you the Window of the embedding element. You can read more about the Window DOM object in the HTML5 spec, http://www.w3.org/TR/html5/browsers.html#the-window-object.FWIW information about cross-document scripting is also available on http://wiki.svg.org.
Erik Dahlström