Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Did IE11 remove javascript conditional compilation?

I have been determining the version of the IE Trident engine using javascript conditional compilation:

var ieVersion = undefined;
/*@cc_on
   ieVersion = Math.floor(@_jscript_version);
@*/

This worked fine for IE8, 9 and 10. In IE11, the conditionally-commented block does not execute, unless I use the F12 dev tools to emulate IE10 (in which case it returns the correct value, 11).

This is confusing, since the MSDN page on conditional compilation specifies that it applies to Internet Explorer 11. (UPDATE 2015-02-03: this page has since been updated to explicitly state that its content does not apply to IE11 in standards mode.) I've not found any information online to suggest that IE11 should not support conditional comments.

Does anyone have any information about this? Can anyone reproduce this behaviour in IE11?


Edit: the relevance of this is in IE's <audio> support. I have a web app that requires playback of around 50 short (~1sec) audio files, which should be played in a (pseudo-)random order, and individually after user interaction. The problems are various:

  • IE9 has an undocumented limit of 41 audio elements (whether declared in HTML or as JS objects). All subsequent audio files silently fail to load and play. (Each of the 41 elements can have its source re-assigned, but every second re-assignment also fails silently. I would love to see the code behind these bugs...)
  • IE10 and IE11 "stutter" when playing short sounds: they play a fraction of a second, then pause, then continue on. The effect to the end-user is that the audio is unintelligible. (The audios have preload="auto" and report a non-zero buffer.)

Naturally there's no practical way to feature-detect these issues, hence the browser-detect. I generally feel user-agent sniffing is too dicey for production code; the @cc_on technique seemed more robust.

My workaround for IE9 is to serialise the app state to sessionStorage after the 25th sound, then reload the page and deserialise.

In IE10/11, my workaround is to play the last 90% of the audio at 0 volume, which seems to force IE to actually buffer the file.

like image 952
Jeremy Avatar asked Dec 05 '13 05:12

Jeremy


People also ask

Does IE 11 support JavaScript?

Internet Explorer 11 doesn't support JavaScript versions later than ES5.

Does promise work in IE?

The Built-In Promise Object ES2015 includes the built-in `Promise` function-object. IE11 does not support this object, so you should use a polyfill like es6-promise.

How do I test Internet Explorer?

Test IE allows you to preview and test websites in all versions of Edge and Internet Explorer (IE6 - IE11). Just click on the extension from the Chrome toolbar, select the Internet Explorer version of your choice, and jumpstart a test session in Browser Live.


1 Answers

Yes, IE11 has removed javascript conditional compilation


The google search linked in the question returns this question as its third result, after two MSDN pages also linked above. This establishes the lack of a better source, so I think this question (including comments) should be considered the authoritative reference for the fact that Javascript conditional compilation is not available in IE11.

I have submitted feedback on the MSDN pages to the effect that they are incorrect.

Update 2015-02-03: MSDN now acknowledges that IE11 no longer supports @cc_on.


Some workarounds are as follows:

User-agent detection

 /\([^)]*Trident[^)]*rv:([0-9.]+)/.exec(ua)

will parse IE11's UA string and return the "revision number" at the end.

ScriptEngineMajorVersion() (thanks @Teemu)

 var tridentVersion = 
     typeof ScriptEngineMajorVersion === "function" ?
         ScriptEngineMajorVersion() : undefined

should evaluate correctly on all browsers, but we can't guarantee ScriptEngineMajorVersion will not be dropped without warning just as conditional compilation has been.


Thanks to all commenters.

like image 104
Jeremy Avatar answered Oct 25 '22 03:10

Jeremy