【发布时间】:2019-02-10 13:27:15
【问题描述】:
我有一个仅支持 chrome 的 angular6 应用程序,但我希望显示用户尝试导航到 IE 中的应用程序的页面/消息,说它不受支持,或者将此链接粘贴到 chrome 中或下载铬。
我是否需要一个 polyfill 以使应用程序能够在 IE 上运行以显示此消息,或者我可以使用某种浏览器检测来仅显示此弹出窗口?
我知道你可以在 TS 中进行浏览器检测,我有,但这意味着我需要一个 IE polyfill,以便应用程序加载甚至显示页面。
// Opera 8.0+
var isOpera = (!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0;
// Firefox 1.0+
var isFirefox = typeof InstallTrigger !== 'undefined';
// Safari 3.0+ "[object HTMLElementConstructor]"
var isSafari = /constructor/i.test(window.HTMLElement) || (function (p) { return p.toString() === "[object SafariRemoteNotification]"; })(!window['safari'] || safari.pushNotification);
// Internet Explorer 6-11
var isIE = /*@cc_on!@*/false || !!document.documentMode;
// Edge 20+
var isEdge = !isIE && !!window.StyleMedia;
// Chrome 1+
var isChrome = !!window.chrome && !!window.chrome.webstore;
// Blink engine detection
var isBlink = (isChrome || isOpera) && !!window.CSS;
var output = 'Detecting browsers by ducktyping:<hr>';
output += 'isFirefox: ' + isFirefox + '<br>';
output += 'isChrome: ' + isChrome + '<br>';
output += 'isSafari: ' + isSafari + '<br>';
output += 'isOpera: ' + isOpera + '<br>';
output += 'isIE: ' + isIE + '<br>';
output += 'isEdge: ' + isEdge + '<br>';
output += 'isBlink: ' + isBlink + '<br>';
document.body.innerHTML = output;
想法?谢谢!
【问题讨论】:
标签: angular typescript browser angular6 browser-detection