gpt4 book ai didi

javascript - 如何检测Internet Explorer 11及以下版本?

转载 作者:数据小太阳 更新时间:2023-10-29 04:02:16 26 4
gpt4 key购买 nike

我想知道如何检测浏览我网站的用户是否使用 Internet Explorer 11 或更低版本的 Javascript。

它应该兼容并适用于所有这些版本。

如何实现?

最佳答案

给你,这应该适合你:

//Per Icycool, one liner
//function isIE(){
// return window.navigator.userAgent.match(/(MSIE|Trident)/);
// }

function isIE() {
const ua = window.navigator.userAgent; //Check the userAgent property of the window.navigator object
const msie = ua.indexOf('MSIE '); // IE 10 or older
const trident = ua.indexOf('Trident/'); //IE 11

return (msie > 0 || trident > 0);
}


//function to show alert if it's IE
function ShowIEAlert(){
if(isIE()){
alert("User is using IE");
}
}

关于javascript - 如何检测Internet Explorer 11及以下版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49986720/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com