如何解决Angular:如果当前浏览器是Internet Explorer,如何重定向到静态unsupported.html页面?
我将此代码放在<script>
中的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支持。您可以检查browser compatibility table。
我建议您使用var
而不是const
来兼容IE 8〜11:
var isIE = /msie\s|trident/i.test(window.navigator.userAgent);
if (isIE) {
window.location.href = "./unsupported.html";
}
测试结果:
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。