搜索

首页  >  问答  >  正文

javascript - 在js中,浏览器关闭还是刷新应该怎么判断?

现在需要判断在浏览器是关闭还是刷新,执行对应操作...

typechotypecho2801 天前769

全部回复(3)我来回复

  • 天蓬老师

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

    刷新调用:Onunload
    关闭调用:onbeforeunload
    可以在<script>脚本中通过window.onunload来指定或者在<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>

    参考:http://www.jianshu.com/p/e920...

    回复
    0
  • 学习ing

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

    load 事件

    回复
    0
  • 伊谢尔伦

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

    load() 方法

    例:

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

    修改后的问题:
    这里有一个和你的问题差不多的,你看看:
    /q/10...

    回复
    0
  • 取消回复