发布网友 发布时间:2022-04-27 04:39
共2个回答
热心网友 时间:2022-04-21 18:13
window.onbeforeunload = onbeforeunload_handler;追问有个问题,我点击别的链接的时候都提示是否离开此页
热心网友 时间:2022-04-21 19:31
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Js智能判断浏览器是关闭还是刷新</title> <meta http-equiv="content-type" content="text/html;charset=gb2312"> </head> <body> 关闭或刷新浏览器试试! <script language="javascript"> window.onbeforeunload=function(){ var n=window.event.screenX-window.screenLeft; var b=n>document.documentElement.scrollWidth-20; if(b&&window.event.clientY<0||window.event.altKey){ alert("关闭"); }else{ alert("刷新"); } } </script> </body> </html>