您现在的位置: 万盛学电脑网 >> 程序编程 >> 脚本专题 >> javascript >> 正文

js离开或刷新页面检测

作者:佚名    责任编辑:admin    更新时间:2022-06-22

 这篇文章主要介绍了js离开或刷新页面检测(且兼容FF,IE,Chrome)。需要的朋友可以过来参考下,希望对大家有所帮助

代码如下: <!DOCTYPE html> <html> <head> <script>   function closeIt()   {     return "Any string value here forces a dialog box to n" +           "appear before closing the window.";   }   window.onbeforeunload = closeIt; </script> </head> <body>   <a href="http://www.jb51.net">Click here to navigate to        www.jb51.net</a> </body> </html>   兼容FF,IE,Chrome的js离开或刷新页面检测,关键的部分是要有return