Results 1 to 2 of 2

Thread: Triggering myself

  1. #1
    Join Date
    Feb 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Triggering myself

    Hi everybody,
    I was playing around this since a while, without any succes, then I left it as it was. Now I have another place, where it would be quite useful for me.

    Let's say, there is an existing div tga.

    I give some content to the innerHTML of the div. The new content has soma javascript code, but as we know, the interpreter will not intrpret the new content. How could I get triggered the div tag from "itself"?

    I would like to get the alert executed... The text appears, but the alert does not... Any idea. Please help me.

    Gregor

    <div id="myid">Old content</div>

    <script>
    oElement = document.getElementById('myid');
    oElement.innerHTML='New content<script>new Function("alert(\'I would like to see this\');");<\/script>';
    </script>
    ____________________
    Proactiv Solution Fine architectural fiberglass columns
    Last edited by sask; 02-05-2007 at 03:17 PM.

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    for(var i = 0, e = oElement.getElementsByTagName("script"); i < e.length; ++i)
      eval(e[i].innerHTML);
    That still won't execute the alert code, I hope you realise, since you've never actually called that function, just created it.

    I suspect this of being a spam post, since it follows the usual pattern, but it appears to be an original question, so I can't prove it.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •