Angular : 如果当前浏览器是 Internet Explorer,如何重定向到静态 unsupported.html 页面?

Angular : How to redirect to a static unsupported.html page if the current browser is Internet Explorer?

我把这段代码放在 index.html 中的 <script> 中。这似乎适用于 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 而不是兼容 IE 8~11 的 const:

var isIE = /msie\s|trident/i.test(window.navigator.userAgent);
if (isIE) {
  window.location.href = "./unsupported.html";
}

测试结果: