Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IFrame causing javascript code to not execute

Does anyone know why this code doesn't work. This means, the alert is NOT fired

<iframe/>
<script type="text/javascript">alert('hello');</script>

While this code with the alert BEFORE the Iframe works perfeclty. This means the alert is fired

<script type="text/javascript">alert('hello');</script>
<iframe/>

Seems that no javascript placed after the iframe is executed, I don't find any logic to this.

like image 599
Claudio Redi Avatar asked Mar 31 '10 18:03

Claudio Redi


1 Answers

You need to close the <iframe> tag like this:

<iframe></iframe>
<script type="text/javascript">alert('hello');</script>
like image 135
hunter Avatar answered Oct 15 '22 15:10

hunter