f5禁止
/*禁止页面刷新*/
document.onkeydown = function()
{
if(event.keyCode==116) {
event.keyCode=0;
event.returnValue = false;
}
}
document.oncontextmenu = function() {event.returnValue = false;}
/* 结束*/
window.location.reload()
Onunload,onbeforeunload都是在刷新或关闭时调用,可以在
2、onunload事件
用法:
·object.onbeforeunload = handler
·
描述:
当用户关闭一个页面时触发 onunload 事件。
触发于:
·关闭浏览器窗口
·通过地址栏或收藏夹前往其他页面的时候
·点击返回,前进,刷新,主页其中一个的时候
·点击 一个前往其他页面的url连接的时候
·调用以下任意一个事件的时候:click,document write,document open,document close,window close ,window navigate ,window NavigateAndFind,location replace,location reload,form submit.
·当用window open打开一个页面,并把本页的window的名字传给要打开的页面的时候。
·重新赋予location.href的值的时候。
·通过input type=”submit”按钮提交一个具有指定action的表单的时候。
示例:
一个判断页面是否真的关闭和刷新的好方法:
window.οnbefοreunlοad=function (){
alert(“===οnbefοreunlοad===”);
if(event.clientX>document.body.clientWidth && event.clientY < 0 || event.altKey){
alert(“你关闭了浏览器”);
}else{
alert(“你正在刷新页面”);
}
}
这段代码就是判断触发onbeforeunload事件时,鼠标是否点击了关闭按钮,或者按了ALT+F4来关闭网页,如果是,则认为系统是关闭网页,否则在认为系统是刷新网页。
还没有评论,来说两句吧...