Note that there are some explanatory texts on larger screens.

plurals
  1. POStupefyingly weird IE 9 Javascript bug: Altering doc title makes subsequent code execute
    text
    copied!<p>I don't understand this at all. Here is some Javascript code that works in every browser but IE 9. It is called from a Flash movie using <code>ExternalInterface</code>, and is meant to dynamically resize the movie in the DOM if the size of the movie changes internally</p> <pre><code>function vResizeFlash(swfId, ht) { document.getElementById(swfId).height = "100%"; document.getElementById('flashContainer').style.height = ht + "px"; } </code></pre> <p>But it works fine if I alter the document.title:</p> <pre><code>function vResizeFlash(swfId, ht) { // IE 9 won't run the rest of this function unless // we go through the charade of changing the document title. if (navigator.appName.indexOf("Microsoft") != -1) { var docTitle = document.title.replace(/^(.+?)\s*$/,"$1"); document.title = docTitle + " "; } // Well-coded browsers begin here document.getElementById(swfId).height = "100%"; document.getElementById('flashContainer').style.height = ht + "px"; } </code></pre> <p>Here I simply trim any white-space from the right side of the <code>document.title</code>, then add a single white-space character to it. Suddenly the following lines get executed. Note: there are other <code>ExternalInterface</code> calls on the page, and all of them work fine, even in IE 9, so it's not a Flash/IE 9 problem.</p> <p>I stumbled on the fix because I was altering the title to show the function arguments (as a quick debugging test), just to make sure the function was getting run. And suddenly the code worked. Take it out? Doesn't work. 100% reproducible.</p> <p>Anybody know <em>why</em> this absolutely stupefying behavior takes place?</p> <p><strong>UPDATE</strong></p> <p>@c69 has posed the question: "Maybe its IE9's dead code remover?"</p> <p>I didn't know about this, so I went and Googled and found <a href="http://arstechnica.com/microsoft/news/2010/11/lies-damned-lies-and-benchmarks-is-ie9-cheating-at-sunspider.ars/2" rel="nofollow noreferrer">this article</a> on the topic, as well as <a href="http://news.ycombinator.com/item?id=1917374" rel="nofollow noreferrer">some discussion</a> of it elsewhere. I don't know enough about it to evaluate how this would affect a two-line Javascript function, however, especially since one of the lines does have a referent on the page (although it is late-loading through the SwfObject code). Still, it would be a pretty bad bug for a code "optimizer" to remove lines of code it deemed unnecessary because it doesn't understand how they are called. And if it <em>did</em> fail to understand how the lines are called, how does inserting a line making a bogus change to the document.title render that code suddenly "necessary"?</p> <p><strong>UPDATE 2</strong></p> <p>Another piece of the puzzle This may have something to do with IE 9's compatibility mode. The page starts out in IE 9's standards mode.</p> <p><img src="https://i.stack.imgur.com/SLRjE.png" alt="enter image description here"></p> <p>Now, if I turn on IE's compatibility mode, </p> <p><img src="https://i.stack.imgur.com/RjTaY.png" alt="enter image description here"></p> <p>the problem goes away without using the above hack. Turn it off, and the problem returns (if no hack present).</p> <p>But when I tried to make a simple test using the exact same HTML (minus a couple of JSP tags) and a stripped down SWF that only contains the resize code and the tools to test, everything works fine. In <em>that</em> case, however, no compatibility icon is displayed at all.</p> <p><img src="https://i.stack.imgur.com/OhE0K.png" alt="enter image description here"></p> <p>We're using Tomcat 6.0.32. I'm not aware that we are using any special headers, and there are no meta tags regarding IE compatibility mode (in either the main app or in my test app).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload