I don't know about the structure of your site, but normally the first script tag is in the . An iframe in the wouldn't be rendered. I'll wager if you did document.body.getElementsByTagName('script')[0] you would probably have similar issues to the one you described above.