views:

129

answers:

1

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.

+3  A: 
<iframe></iframe>
<script type="text/javascript">alert('hello');</script>
hunter
I should add that the reason this is the answer is that <iframe/> is not really a valid tag. They can't be closed in that fashion.
Tesserex
you did it. thanks man!
Claudio Redi
They can be closed in that fashion, but only in XHTML, and not in HTML-compatible XHTML (i.e. HTML served as text/html so that Internet Explorer will parse it because it doesn't support XHTML)
David Dorward
@hunter: I have to wait some minutes in order to be allowed to accept an answer, Stack Overflow rules. Not sure why they did it like this.
Claudio Redi
@Claudio - oh! sorry!
hunter