在JS中加入:window.onbeforeunload = function(evt) {
alert("onbeforeunload");
}发现关闭网页时没有弹出alert,为什么?
我还测试了一下网上的代码,如下,也不行。 window.onbeforeunload = function(evt) {
if ($("#SmallChanged").val() == "true") {
evt = evt || window.event;
if (window.event) {
if (evt.clientX > document.documentElement.clientWidth && evt.clientY < 0 || evt.altKey)
evt.returnValue = "Do you want to leave this page without saving?";
}
else {
if (clientH < 222)
evt.returnValue = "Do you want to leave this page without saving?";
}
}
} document.onmousemove = function(e) {
e = e || window.event;
if (e != window.event) {
clientW = e.pageX;
clientH = e.pageY;
}
}
alert("onbeforeunload");
}发现关闭网页时没有弹出alert,为什么?
我还测试了一下网上的代码,如下,也不行。 window.onbeforeunload = function(evt) {
if ($("#SmallChanged").val() == "true") {
evt = evt || window.event;
if (window.event) {
if (evt.clientX > document.documentElement.clientWidth && evt.clientY < 0 || evt.altKey)
evt.returnValue = "Do you want to leave this page without saving?";
}
else {
if (clientH < 222)
evt.returnValue = "Do you want to leave this page without saving?";
}
}
} document.onmousemove = function(e) {
e = e || window.event;
if (e != window.event) {
clientW = e.pageX;
clientH = e.pageY;
}
}
if(event.clientX> document.body.clientWidth&&event.clientY <0||event.altKey)
{
alert( "确定要关闭吗 ");
}
}
</script>
<script type="text/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>
if( event.clientX>document.body.clientWidth && event.clientY<0 || event.altKey ) {
}else if(event.clientY > document.body.clientHeight || event.altKey)
{
}
}