search

Home  >  Q&A  >  body text

javascript - How to judge whether the browser is closed or refreshed in js?

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

typechotypecho2751 days ago739

reply all(3)I'll reply

  • 天蓬老师

    天蓬老师2017-06-12 09:33:54

    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...

    reply
    0
  • 学习ing

    学习ing2017-06-12 09:33:54

    load event

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-06-12 09:33:54

    load() method

    Example:

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

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

    reply
    0
  • Cancelreply