PDA

View Full Version : innerHTML script



Kofgarter
01-12-2009, 06:05 PM
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/

diltony
01-12-2009, 08:39 PM
Corrected version




<HTML>
<script>

function insertScript(){
var sHTML="<input type=button onclick='" + "go2()'" + " value='Click Me'><BR>";
var sScript="function go2() {alert('Hello from inserted script.') }";

eval(sScript);
window.go2=go2;

ScriptDiv.innerHTML = sHTML;
}
</SCRIPT>
<BODY onload="insertScript();">

<DIV ID="ScriptDiv"></DIV>
</BODY>
</HTML>



This one should do it.

Kofgarter
01-12-2009, 09:16 PM
yep, it's work!! Thanks, I'm appreciate your help!;)