javascript - 使用 Internet Explorer 时始终显示更新通知
问题描述
我刚刚发现这个方便的网站可以向用户显示通知以更新他们的浏览器(如果它们已过时),但在 mi 网站上我需要使用 HTML 5 而 Internet Explorer 不支持它
有谁知道是否可以在使用 Internet Explorer 时始终显示通知但允许在其他浏览器上进行提醒冷却?
到目前为止,我的代码是这样的:
var $buoop = {required:{e:-4,f:-3,o:-3,s:-1,c:-3},insecure:true,unsupported:true,api:2020.08,text_for_i: {
'msg':'Tu navegador {brow_name} ya no es soportado.',
'msgmore': 'Por favor utiliza otro navegador para poder usar nuestro sitio.'
} };
function $buo_f(){
var e = document.createElement("script");
e.src = "//browser-update.org/update.min.js";
document.body.appendChild(e);
};
try {document.addEventListener("DOMContentLoaded", $buo_f,false)}
catch(e){window.attachEvent("onload", $buo_f)}
解决方案
根据您的描述,如果用户使用的是任何版本的 IE 浏览器,那么您希望向用户显示使用任何其他浏览器的通知。
我建议您参考下面的示例,这可能会帮助您获得所需的结果。
<!doctype html>
<html>
<head>
<script>
//detects if user uses Internet Explorer
//returns version of IE or false, if browser is not IE
//Function to detect IE or not
function IEdetection() {
var ua = window.navigator.userAgent;
var msie = ua.indexOf('MSIE ');
if (msie > 0) {
// IE 10 or older, return version number
return ('Tu navegador IE ' + parseInt(ua.substring(
msie + 5, ua.indexOf('.', msie)), 10) + ' ya no es soportado. Por favor utiliza otro navegador para poder usar nuestro sitio.');
}
var trident = ua.indexOf('Trident/');
if (trident > 0) {
// IE 11, return version number
var rv = ua.indexOf('rv:');
return ('Tu navegador IE ' + parseInt(ua.substring(
rv + 3, ua.indexOf('.', rv)), 10) + ' ya no es soportado. Por favor utiliza otro navegador para poder usar nuestro sitio.');
}
// User uses other browser
return ('Welcome...');
}
var result = IEdetection();
document.write(result);
</script>
</head>
<body>
<h2>Test page...</h2>
</body>
</html>
IE浏览器输出:
参考:
推荐阅读
- c# - 后续 http 请求后 TempData 仍然可用吗?
- angular - 如何在 Angular 7 中处理嵌套的 HTTP 请求?
- javascript - 在 map 函数中切换条件语句
- java - File.lastmodified() 生成错误的日期和月份
- c# - 读取一个文本文件,直到一行包含一些字符串文件,然后再次继续读取下一行,直到遇到另一个字符串
- powershell - Start-AzureRmDataFactoryV2Trigger 触发器 XXX 具有意外的资源提供程序:、意外的资源类型,或两者兼有
- android - 如何在xml中隐藏另一个组件后面的布局?
- node.js - 将基本身份验证与 loopback.js 和 ldap 一起使用
- r - 折线图 ggplot - 两条线,来自同一站点/秒的数据点
- python - 使用 python-requests 请求时出现 SSL 错误