IE11是否删除了javascript条件编译? [英] Did IE11 remove javascript conditional compilation?

查看:107
本文介绍了IE11是否删除了javascript条件编译?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用 javascript条件编译

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

这适用于IE8,9和10.在IE11中,有条件评论的块不执行,除非我使用F12开发工具来模拟IE10(在这种情况下,它返回正确的值,11)。

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).

这令人困惑,因为条件编译的MSDN页面 指定它适用于Internet Explorer 11 。 (更新2015-02-03 :此页面已更新为明确声明其内容 未在标准模式下应用于IE11。)我未在网上找到任何信息,表明IE11不应支持条件评论。

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.

有没有人有任何相关信息?任何人都可以在IE11中重现这种行为吗?

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

编辑:这与IE的<相关; audio> 支持。我有一个网络应用程序需要播放约50个短(~1秒)音频文件,这些文件应以(伪)随机顺序播放,并在用户交互后单独播放。问题是多种多样的:

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的未记录限制为41 audio 元素(无论是在HTML中声明还是作为JS对象声明)。所有后续音频文件都无法加载和播放。 (41个元素中的每一个都可以重新分配它的源,但是每一次重新分配也会无声地失败。我很想看到这些错误背后的代码......)

  • IE10播放短音时IE11口吃:它们只播放一小段时间,然后暂停,然后继续播放。对最终用户的影响是音频难以理解。 ( audio s有 preload =auto并报告非零缓冲区。)

  • 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.)

当然,没有实用的方法来检测这些问题,因此浏览器检测。我一般认为用户代理嗅探对于生产代码来说过于冒险; @cc_on 技术似乎更强大。

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.

我对IE9的解决方法是将应用程序状态序列化为<$ c $ 25> sessionStorage 在第25个声音之后,然后重新加载页面并反序列化。

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

在IE10 / 11中,我的解决方法是播放最后一个90%的音频在0音量,这似乎迫使IE 实际上缓冲文件。

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.

推荐答案

< h2>是的,IE11删除了javascript条件编译




谷歌搜索在问题中链接返回此问题作为其第三个结果,在上面链接了两个MSDN页面之后。这确定了缺乏更好的来源,所以我认为这个问题(包括评论)应该被认为是IE11中没有Javascript条件编译这一事实的权威参考。

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.

我已经在MSDN页面上提交了反馈,说明它们不正确。

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

更新2015-02-03 MSDN 现在承认IE11不再支持 @cc_on

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

一些解决方法如下:

用户代理检测

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

将解析IE11的UA字符串并在结尾返回修订号。

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

ScriptEngineMajorVersion() (感谢@Teemu)

ScriptEngineMajorVersion() (thanks @Teemu)

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

应该在所有浏览器上正确评估,但我们不能保证 ScriptEngineMajorVersion 不会在没有警告的情况下被删除,就像条件编译一样。

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

感谢所有评论者。

这篇关于IE11是否删除了javascript条件编译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆