Stupefyingly weird IE 9 JavaScript error: changing the name of the document makes subsequent code execution

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 ExternalInterface and is designed to dynamically resize a movie in the DOM if the movie resizes inside

 function vResizeFlash(swfId, ht) { document.getElementById(swfId).height = "100%"; document.getElementById('flashContainer').style.height = ht + "px"; } 

But it works fine if I modify document.title:

 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"; } 

Here I just crop any white space on the right side of document.title , and then add one space character to it. The following lines are suddenly executed. Note. There are other ExternalInterface calls on the page, and they all work fine, even in IE 9, so this is not a Flash / IE 9 problem.

I came across a fix because I changed the title to show the arguments of the function (as a quick debugging test) to make sure the function starts. And suddenly the code worked. Take it out? Does not work. 100% reproducible.

Does anyone know why this absolutely intoxicating behavior occurs?

UPDATE

@ c69 posed the question: "Maybe its IE9 with remote code?"

I did not know about this, so I went and went to Google and found this article on this topic, as well as a discussion elsewhere. I don’t know enough about this to evaluate how this will affect the two-line Javascript function, especially since one of the lines has a reference on the page (although this is a late load through SwfObject code). However, it would be a good mistake for the code “optimizer” to delete lines of code that he considered unnecessary because he does not understand how they are called. And if he did not understand how the lines are called, how does inserting a line creating dummy changes in document.title render this code suddenly “necessary”?

UPDATE 2

Another piece of the puzzle. This may have something to do with IE 9 compatibility mode. The page starts in IE 9 standards mode.

enter image description here

Now, if I turn on IE compatibility mode,

enter image description here

the problem disappears without using the above hack. Turn it off, and the problem will return (if there is no hacking).

But when I tried to do a simple test using the same HTML (minus a few JSP tags) and devoid of SWF, which only contains resizing code and testing tools, everything worked fine. However, in this case, the compatibility icon is not displayed at all.

enter image description here

We are using Tomcat 6.0.32. I don’t know that we use special headers and there are no meta tags regarding IE compatibility mode (in the main application or in the test application).

+44
javascript internet-explorer internet-explorer-9
Sep 20 2018-11-11T00:
source share
2 answers

as InvertedSpear is mentioned, check the type of your document, I have had problems with IE9 lately, and most of them came down to Doc type tags launching compatibility mode that I don’t need, the same can be said about meta tags so that it could come down to your meta tags.

You can always impose an operational compatibility mode using the links below.

from: http://evolpin.wordpress.com/2011/02/25/ie9-compatibility-and-the-meta-tag/

Ive discovered that this is indeed documented by Microsoft ...

http://msdn.microsoft.com/en-us/library/cc288325(VS.85).aspx

"The X-UA compatible header is not case sensitive, but it should appear in the web page header (HEAD section) before all other elements except the title element and other meta elements."

+2
Sep 30 2018-11-11T00:
source share

Whenever I see that this happens in any language, it is because there is other code that has an error. As you pointed out, your simple case does not pose a problem. Try removing another code a few lines at a time until the problem goes away - the last deleted code should contain the problem.

Greetings

+2
Sep 30 '11 at 16:01
source share



All Articles