js关闭手机浏览器页面

最新推荐文章于 2024-04-26 17:03:05 发布

今天明天kevin

最新推荐文章于 2024-04-26 17:03:05 发布

阅读量3.1k

收藏

1

点赞数

1

CC 4.0 BY-SA版权

文章标签:

javascript

原文链接:https://blog.csdn.net/weixin_45289067/article/details/103146674?utm_medium=distribute.pc_relevant_bbs_down.none-task--2~all~first_rank_v2~rank_v29-2.nonecase&depth_1-utm_source=distribute.pc_relevant_bbs_down.none-task--2~all~first_rank_v2~rank_v29-2.none

本文介绍了一种处理不同浏览器兼容性的JavaScript脚本实现方法,主要针对IE6及更高版本的IE浏览器、Firefox以及其他现代浏览器。通过特定的条件判断,该脚本能够有效地关闭或重新定向不符合预期行为的浏览器窗口。

摘要生成于

C知道

,由 DeepSeek-R1 满血版支持,

前往体验 >

if (navigator.userAgent.indexOf("MSIE") > 0) {

if (navigator.userAgent.indexOf("MSIE 6.0") > 0) {

window.opener = null;

window.close();

}

else {

window.open('', '_top');

window.top.close();

}

}

else if (navigator.userAgent.indexOf("Firefox") > 0) {

window.location.href = 'about:blank '; //火狐默认状态非window.open的页面window.close是无效的

//window.history.go(-2);

}

else {

window.opener = null;

window.open('', '_self', '');

window.close();

}