javascript - How to judge whether the browser is closed or refreshed in js?
typecho
typecho 2017-06-12 09:31:54
0
3
738

Now we need to determine whether the browser is closed or refreshed, and perform the corresponding operation...

typecho
typecho

Following the voice in heart.

reply all(3)
Peter_Zhu

Refresh call:Onunload
Close call:onbeforeunload
Can be specified in the <script> script through window.onunload or specified in <body>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>


</body>
    <script>
        window.onbeforeunload = function(){ 
            return "quit?"; 
        }
  </script>
</html>

Reference: http://www.jianshu.com/p/e920...

学习ing

load event

伊谢尔伦

load() method

Example:

$("img").load(function(){
  $("p").text("Image loaded");
});

Modified question:
Here is a question similar to yours, take a look:
/q/10...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template