Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
432 views
in Technique[技术] by (71.8m points)

internet explorer - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...