Why does this [removed] iframe ads code completely break Internet Explorer?

前端 未结 6 1119
青春惊慌失措
青春惊慌失措 2021-02-13 14:19

So, I\'m trying to find an answer to why this problem is happening; I\'ve fixed the problem, but I want to know why it happened.

TL;DR

Google-provided conversi

相关标签:
6条回答
  • 2021-02-13 14:39

    I've solved the problem; it turns out that it had nothing to do with the contents of the <iframe>.

    It turns out the page is served by a framework that began using a backend DOM parser that, for reasons likely related to the presence of </ within a <script> tag within the document.write, completely removes the </iframe> closing tag from the generated page, even though it preserves it in the backend. (It's probably trying to enforce ETAGO rules).

    The reason I was able to reproduce it was because I was copying the generated document.write code, not the original code, and never noticed the missing </iframe>. (And my "functioning" document.write code didn't have the stripped out </iframe> tag, leading me to believe that the problem was the contents of the iframe.)

    As a result, browsers parsed an unclosed <iframe> tag on the page, which Internet Explorer didn't know how to handle, and died part way through the parsing of the iframe (I'm still not totally sure why).

    0 讨论(0)
  • 2021-02-13 14:39

    I tried replicating your issue but couldn't on IE9.

    Either I don't have the right test setup or it seems IE prior to IE 9 had some bug. Firefox had a simialr bug: https://bugzilla.mozilla.org/show_bug.cgi?id=293633

    Maybe its a combination of unclosed iframe and something inside the page that's being rendered.

    0 讨论(0)
  • 2021-02-13 14:43

    document.write() blocks further page rendering until it finishes. I assume that the remote script was taking a while to load, and thus blocking the rest of the page from loading.

    I also assume that Math.Random() function doesn't help matters.

    Also...Google's tracking codes scare me...they tend to be ugly hacks of javascript.

    0 讨论(0)
  • 2021-02-13 14:47

    I don't know about the structure of your site, but normally the first script tag is in the <head>. An iframe in the <head> 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.

    0 讨论(0)
  • 2021-02-13 14:49

    There is 2 reasons why the first method should be slow.

    • document.write() blocks until it is actually performed
    • the window’s onload event doesn’t fire until all its iframes, and all the resources in these iframes, have fully loaded

    Your solution works because the iframe it creates does not request the remote url until after the onload event. Having a set timeout on the first code, you would also get the page to load, then the request to the remote url to fire.

    As to why the change of code broke the site, I can not seem to find any speed differences transferring between the two. Maybe it seemed faster because it was cached.

    0 讨论(0)
  • 2021-02-13 14:56

    Seems you're having a similar problem that I had several months back. The document.write triggers, and overwrites the page. Just use the iframe directly, and everything should be kosher.

    0 讨论(0)
提交回复
热议问题