help me please, make work this script for Firefox! I know that it is possible, but don't know how to make it right =(( <HTML> <script> function insertScript(){ var sHTML="<input type=button onclick=" + "go2()" + " value='Click Me'><BR>"; var sScript="<script DEFER>"; sScript = sScript + "function go2(){ alert('Hello from inserted script.') }"; sScript = sScript + "</SCRIPT" + ">"; ScriptDiv.innerHTML = sHTML + sScript; } </SCRIPT> <BODY onload="insertScript();"> <DIV ID="ScriptDiv"></DIV> </BODY> </HTML> sources: http://msdn.microsoft.com/en-us/library/ms533897(VS.85).aspx http://www.julienlecomte.net/blog/2007/12/38/
ScriptDiv.innerHTML = sHTML + sScript; wrong. use document.getElementById("ScriptDiv"): this is reported back in firefox, i don't think it can be any clearer... you may have to install firebug (www.getfirebug.com) to debug in firefox. also, the fact that you update an element's innerHTML does not evaluate the script automatically. in fact, i'd consider this a security issue - which is probably why if you fix the fatal error, you end up with "go2 is undefined".
Kofgarter, what is your intention with this script? Maybe we can help by writing the proper code so you can accomplish this.
And remember to always put document. in front, if not - firefox and other browsers than IE wont parse it right
you are doing it hard wasy function myhtml() { var html = "This is my text and this is my double quota \" add quota mark with slash and the quota mark like this - \" and then end of var with closed quota "; document.getElementById("mydiv").innerHTML = html; } <body onlaod="myhtml()"> <div id="mydiv"></div> HTML:
Should be: ....... <script type="text/javascript"> function myhtml(){ var html = "This is my text and this is my double quota \" add quota mark with slash and the quota mark like this - \" and then end of var with closed quota "; document.getElementById("mydiv").innerHTML = html; } </script> </head> <body onload="myhtml()"> <div id="mydiv"></div> ....... HTML:
Sorry for the bump, i just want to let all the members know that the fix by elias_sorensen is working! Thanks