浏览器窗口关闭事件的监听搜集
方式一:(适用与IE浏览器,而且刷新不提示,只在点击浏览器关闭按钮的时候提示)
<script type="text/javascript">
window.onbeforeunload=onclose;
function onclose()
{
if(event.clientX>document.body.clientWidth&&event.clientY<0||event.altKey)
{
return "您要离开吗?";
}
}
</script>
----------------------------------------------------------------------------------------------------
方式二:适用与IE和FF,不区分刷新和关闭
<script type="text/javascript">
window.onbeforeunload = onbeforeunload_handler;
window.onunload = onunload_handler;
function onbeforeunload_handler(){
var warning="确认退出?";
return warning;
}
function onunload_handler(){
var warning="谢谢光临";
alert(warning);
}
</script>
---------------------------------------------------------------------------------------------------
方式三:适用与IE和FF,不区分刷新和关闭,最简单的
<script type="text/javascript">
window.onbeforeunload=onclose;
function onclose()
{
return "您确定退出吗?";
}
</script>
---------------------------------------------------------------------------------------------------
方式四:适用与IE和FF,不区分刷新和关闭,稍复杂的
<script language="javascript">
var MSG_UNLOAD="如果你此时离开档案系统,所做操作信息将全部丢失,是否离开?";
var UnloadConfirm = {};
//启用监听浏览器刷新、关闭的方法
UnloadConfirm.set = function(confirm_msg){
window.onbeforeunload = function(event){
event = event || window.event;
event.returnValue = confirm_msg;
}
}
//关闭监听浏览器刷新、关闭的方法
UnloadConfirm.clear = function(){
window.onbeforeunload = function(){};
}
UnloadConfirm.set(MSG_UNLOAD);
</script>
--------------------------------------------------------------------------------------------------
方式五:只适用于IE6下的关闭按钮和快捷键关闭的,刷新不提示
<script type="text/javascript">
window.onbeforeunload=onclose;
function onclose()
{
var warnning = '<fmt:message key="systemMessage.exitWarning" />';
var beforeExit='<fmt:message key="systemMessage.beforeExitWarning" />';
if(event.clientY<0 && event.clientX>document.body.clientWidth-20 || event.clientY<0 && event.clientX<20 ||
event.altKey || event.ctrlKey || event.clientY>document.body.clientHeight){
alert(beforeExit);
return warnning;
}
}
</script>
****************************************************************************************************
另附判断浏览器类型的JS
<script type="text/javascript">
var Sys = {};
var ua = navigator.userAgent.toLowerCase();
&
相关新闻>>
- 发表评论
-
- 最新评论 更多>>