Javascript 角度:如果当前浏览器是Internet Explorer,如何重定向到静态的unsupported.html页面?
我把这段代码放在Javascript 角度:如果当前浏览器是Internet Explorer,如何重定向到静态的unsupported.html页面?,javascript,angular,internet-explorer,browser,Javascript,Angular,Internet Explorer,Browser,我把这段代码放在index.html中的中。这似乎适用于IE版本10以上 const isIE = /msie\s|trident/i.test(window.navigator.userAgent); if (isIE) { window.location.href = "./unsupported.html"; } 但是对于版本8和版本9,我只得到一个空白页 有没有办法让它也适用于旧的IE版本?该代码在IE 8~9中不起作用,因为const仅受IE 11支持。你可以
index.html
中的
中。这似乎适用于IE版本10以上
const isIE = /msie\s|trident/i.test(window.navigator.userAgent);
if (isIE) {
window.location.href = "./unsupported.html";
}
但是对于版本8和版本9,我只得到一个空白页
有没有办法让它也适用于旧的IE版本?该代码在IE 8~9中不起作用,因为
const
仅受IE 11支持。你可以查一下电话号码
我建议您使用var
而不是与IE 8~11兼容的const
:
var isIE = /msie\s|trident/i.test(window.navigator.userAgent);
if (isIE) {
window.location.href = "./unsupported.html";
}
测试结果: