Results 1 to 3 of 3

Thread: innerHTML script

  1. #1
    Join Date
    Jan 2009
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default innerHTML script

    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/libr...97(VS.85).aspx
    http://www.julienlecomte.net/blog/2007/12/38/

  2. #2
    Join Date
    Dec 2008
    Location
    Nigeria
    Posts
    95
    Thanks
    3
    Thanked 8 Times in 8 Posts

    Default

    Corrected version

    Code:
    <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.

  3. The Following User Says Thank You to diltony For This Useful Post:

    Kofgarter (01-12-2009)

  4. #3
    Join Date
    Jan 2009
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    yep, it's work!! Thanks, I'm appreciate your help!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •