简体   繁体   English

有没有办法警告使用IE版本不支持的JavaScript功能?

[英]Is there a way to warn about using JavaScript features not supported in IE versions?

I am working in a shop that uses Typescript for most new development so we are very used to using ES6 features like arrow functions and have them made safe for Internet Explorer by the transpilation step. 我在一家使用Typescript进行大多数新开发的商店里工作,所以我们非常习惯使用箭头功能之类的ES6功能,并通过转换步骤使它们对于Internet Explorer而言是安全的。 But this week I had to edit an existing js file (which has no transpilation) and stupidly used an arrow function. 但是这周我不得不编辑一个现有的js文件(没有转译),并且愚蠢地使用了箭头功能。 This worked fine in my modern development browsers, but broke in QA under IE 9. 这在我的现代开发浏览器中工作正常,但是在IE 9下进行了质量检查。

So I know this is my dumb mistake, but I am wondering if there is tooling that can warn if features that do not meet a particular browser version are used to use as double check? 因此,我知道这是我的愚蠢错误,但是我想知道是否有工具可以警告是否使用不符合特定浏览器版本的功能来进行双重检查? If this has a Visual Studio integration that would be wonderful, but I have no problem adding a command line step to my work flow. 如果它具有Visual Studio集成,那就太好了,但是我没有问题,可以在我的工作流程中添加命令行步骤。 I looked at ESHint but didn't see that sort of rule. 我看着ESHint,但没有看到这样的规则。

If you're just talking IE (I know nothing of Typescript) and Visual Studio, you can use the following in VS: 如果您只是在谈论IE(我对Typescript一无所知)和Visual Studio,则可以在VS中使用以下内容:

    WinPath = System.Environment.GetEnvironmentVariable("SystemRoot")   ''MsgBox(WinPath)

    On Error Resume Next

    Dim ver = FileVersionInfo.GetVersionInfo(WinPath & "\system32\ieframe.dll")
    Dim IE = Val(ver.ProductVersion) ''MsgBox(IE)

This will return the local machine IE version - is this what you want? 这将返回本地计算机的IE版本-这是您想要的吗?

If not, Javascript can detect which browser it is being used by with this script: 如果不是,则Javascript可以检测到该脚本正在使用哪个浏览器:

var browser=navigator.userAgent;
var IE=browser.search(/(MSIE ?[7891]|Trident|Edge\/)/i);    //=-1: not MS
if (IE!=-1) {
    T=browser.substr(IE,7);
    if (T.search(/^M/)==0) IE=parseInt(T.substr(4));
    else if (T.search(/^T/)==0) IE=11;
    else IE=12; //Edge
}
else IE=13; //not IE,Edge

Put it your onload function and react accordingly (OK, so it only does IE version, Edge, or other... but ...) 将其放在您的onload函数中并做出相应的反应(好吧,所以它仅适用于IE版本,Edge或其他版本,但是...)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Facebook图形API调用中,使用Javascript的IE(所有版本)不支持跨浏览器调用 - In Facebook graph API Call Cross browser call not supported in IE(all versions) using Javascript 在旧版Internet Explorer(IE)中测试javascript小书签的最佳方法 - best way to test javascript bookmarklets in older versions of internet explorer (IE) 了解 >0.2% 时的含义并找到支持的 IE 版本 - Understanding the meaning if >0.2% and finding the IE versions supported 使用 ESLint 防止在 IE11 中使用不受支持的 JavaScript 功能? - Prevent use of unsupported JavaScript features in IE11 using ESLint? 对nodejs版本和javascript版本感到困惑 - Confused about nodejs versions and javascript versions 如何确定IE的相对最新版本的高度和宽度(是,IE8不喜欢从JavaScript设置此样式?) - How can I determine height and width for relatively recent versions of IE (was, what does IE8 not like about setting this style from JavaScript?) IE中不支持JavaScript对象属性? - JavaScript object property not supported in IE? 我如何在IE7,IE8,Safari和其他受支持的浏览器中使用JavaScript播放.Wav声音 - how I play .Wav sound in IE7,IE8,Safari and other supported browser using javascript 使用 typescript 定义文件 (.d.ts) 键入 javascript 代码不会警告原始类型错误 - using typescript definition file (.d.ts) for typing javascript code doesn't warn about primitive type errors 有没有人警告过JavaScript的副作用? - Any linter to warn about side-effects in JavaScript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM