javascript - ASP.NET MVC;Javascript;HTML:如何制作一个关闭浏览器的自己的按钮?
问题描述
如何制作关闭浏览器的按钮?下面的代码不适用于我的 ASP.NET MVC 应用程序。我已经在 Mozilla、Chrome 和 Edge 上对其进行了测试。
<!DOCTYPE html>
<body>
<input type="submit" id="btnCloseScreen" name="btnCloseScreen" value="X" style="font-size:large; font-weight:bold; background-color:red; width:30px; border-color:#3f464c; height:30px" />
</body>
$("#btnCloseScreen").click(function () {
var Browser = navigator.appName;
var indexB = Browser.indexOf('Explorer');
if (indexB > 0) {
var indexV = navigator.userAgent.indexOf('MSIE') + 5;
var Version = navigator.userAgent.substring(indexV, indexV + 1);
if (Version >= 7) {
window.open('', '_self', '');
window.close();
}
else if (Version == 6) {
window.opener = null;
window.close();
}
else {
window.opener = '';
window.close();
}
}
else {
window.open('', '_self', ''); window.close();
}
}
</script>
解决方案
推荐阅读
- javascript - 是否应该在节点中收听 http.ClientReuqest 的“错误”事件?
- arrays - 将数据从 .csv 传输到结构数组,然后对其进行排序以将其保存在不同的文件中
- .htaccess - 三星 Tizen 智能电视浏览器上的 HTML5 视频不工作和扩展黑客
- spring-webflux - 带有 Spring Webflux 的 Project Reactor 中的调度程序
- python - Twitter 情绪分析常数零 (0.0000e+00) 损失值
- asp.net-core - Blazor StateHasChanged() 未更新子组件
- javascript - 如何在使用 setTimeout 执行的 if 条件中将 css 应用于列表的文本项?(文本滑块)
- javascript - 指纹解锁应用程序解锁门锁(物联网项目)
- sql - 找到所有有红球和蓝球的罐子
- sql - 如何提高我的 postgresql 查询的性能?