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
audio
s 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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…