PDA

View Full Version : Triggering myself



sask
02-02-2007, 12:06 PM
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 (http://www.crescatsententia.org) Fine architectural fiberglass columns (http://www.worthingtonmillwork.com)

Twey
02-02-2007, 01:45 PM
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.