Posted by petersprc on 06/20/07 10:39
It would be easier to separate the text and the script and call eval
on the script part.
Problem is the browser can't be counted on to evaluate your embedded
scripts. Here's a workaround:
http://kratcode.wordpress.com/2006/03/07/javascript-script-execution-in-innerhtml-the-revenge/
On Jun 20, 2:10 am, Pratik Patel <anay.pra...@gmail.com> wrote:
> Hello,
>
> I used innerHTML to assign HTML content. but in my HTML page content
> have also some javascript function and it will run when page load. bu
> when HTML code assgin thru innerHTML then this javascript is not
> working.
>
> e.g.
>
> html content:
> .....................
> <html>
> <body>
> <table>
> <tr><td>
> Some content here.
> </td></tr>
> </table>
> <script language="javascript">
> alert("hi");
> </script>
> </body>
> </html>
>
> I am assign this html page in innerHTML content
>
> document.getElementById('div1').innerHTML="<html><body><table><tr><td>Some
> content here.</td></tr></table><script
> language="javascript">alert("hi");</script></body></html>";
>
> when i used direct html page it's given alert message. but when i used
> theu innerHTML then it's not given alert message.
>
> how i can execute javascript in innerHTML?can anyone help?
>
> Regards
> Pratik Patel
[Back to original message]
|