[Project_owners] Adding a script to an iframe

Michael Vincent van Rantwijk noreply at yahoo.com
Thu Mar 1 08:14:25 PST 2007


Gareth Hunt wrote:
> Hi all,
> 
> I have an iframe in a xul document that I need to add a javascript
> reference to on the fly.  I am adding the script using:
> 
> var myIframe = document.getElementById("myIframe")
> var head =
> myIframe.contentDocument.getElementsByTagName("head").item(0)
> 
> var script = myIframe.contentDocument.createElement("script")
> script.type = "application/x-javascript"
> script.src = "chrome://app/content/my.js"
> head.appendChild(script)
> 
> This follows an example at:
> http://www.dhtmlcentral.com/tutorials/tutorials.asp?id=11 . The
> difference is that I am attempting to add the script to an iframe
> contained within a xul document.
> 
> If I examine the iframe DOM after the insertion, the script is there in
> the source, but the functions in the script are not available when
> called.
> 
> Does anyone have any ideas?

nsIScriptLoader.idl


More information about the Project_owners mailing list