lvyan
V2EX  ›  问与答

关于页面关闭是事件

  •  
  •   lvyan · Apr 18, 2014 · 2981 views
    This topic created in 4458 days ago, the information mentioned may be changed or developed.
    window.onbeforeunload=function (){
    alert("===onbeforeunload===");
    if(event.clientX>document.body.clientWidth && event.clientY < 0
    event.altKey){
    alert("你关闭了浏览器");
    }else{
    alert("你正在刷新页面");
    }
    }
    为什么不执行里面的alert???
    5 replies    1970-01-01 08:00:00 +08:00
    jsonline
        1
    jsonline  
       Apr 18, 2014 via Android   ❤️ 1
    是的,这个事件里不准写alert和异步代码,你直接return一个字符串看看
    yimity
        2
    yimity  
       Apr 18, 2014   ❤️ 1
    来不及执行。
    lvyan
        3
    lvyan  
    OP
       Apr 18, 2014
    呃 好吧。。
    lvyan
        4
    lvyan  
    OP
       Apr 18, 2014
    return倒是可以。。
    lvyan
        5
    lvyan  
    OP
       Apr 18, 2014
    @jsonline 有没有其它的办法可以判断当页面关闭时执行一个函数??
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3143 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 40ms · UTC 14:10 · PVG 22:10 · LAX 07:10 · JFK 10:10
    ♥ Do have faith in what you're doing.