我在javascript里面加入了这样一段代码
function window.onunload()
{
if(event.clientX>document.body.clientWidth&&event.clientY<0||event.altKey||event.ctrlKey)
{
alert('关闭');
}
else{
alert("刷新");
} } 但是不管我是刷新还是关闭网页,都只弹出 “刷新” ,不能弹出关闭
各位大哥帮忙解决一下这个问题,就是把刷新和关闭区分出来
function window.onunload()
{
if(event.clientX>document.body.clientWidth&&event.clientY<0||event.altKey||event.ctrlKey)
{
alert('关闭');
}
else{
alert("刷新");
} } 但是不管我是刷新还是关闭网页,都只弹出 “刷新” ,不能弹出关闭
各位大哥帮忙解决一下这个问题,就是把刷新和关闭区分出来
Navigate to another location by entering a new address or selecting a Favorite.
Click the Back, Forward, Refresh, or Home button. 所以刷新和关闭应该是不能区分的
function CloseOpen(event) {
if(event.clientX<=0 && event.clientY<0) {
alert("关闭");
}else{
alert("刷新或离开");
}
}
或
window.onbeforeunload = function() //author: meizz
{
var n = window.event.screenX - window.screenLeft;
var b = n > document.documentElement.scrollWidth-20;
if(b && window.event.clientY < 0 || window.event.altKey){
alert("是关闭而非刷新");
window.event.returnValue = ""; //这里可以放置你想做的操作代码
}else{
alert("是刷新而非关闭");
}
}
参考于:http://www.javaeye.com/topic/269213
{
var n = window.event.screenX - window.screenLeft;
var b = n > document.documentElement.scrollWidth-20;
if(b && window.event.clientY < 0 || window.event.altKey){
alert("是关闭而非刷新");
window.event.returnValue = ""; //这里可以放置你想做的操作代码
}else{
alert("是刷新而非关闭");
}
}
上面代码要求的是一个浏览器只有一个网页,而ie7是一个浏览器有多个网页标签,这样的话上面的代码就行不通了