lvyan
V2EX  ›  问与答

关于页面关闭是事件

  •  
  •   lvyan · Apr 18, 2014 · 3236 views
    This topic created in 4590 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
    jsonline
    Apr 18, 2014 via Android❤️1
    1
    是的,这个事件里不准写alert和异步代码,你直接return一个字符串看看
    yimity
    yimity
    Apr 18, 2014❤️1
    2
    来不及执行。
    lvyan
    lvyan
    OP
    Apr 18, 2014
    3
    呃 好吧。。
    lvyan
    lvyan
    OP
    Apr 18, 2014
    4
    return倒是可以。。
    lvyan
    lvyan
    OP
    Apr 18, 2014
    5
    @jsonline 有没有其它的办法可以判断当页面关闭时执行一个函数??
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   4570 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 06:35 · PVG 14:35 · LAX 22:35 · JFK 01:35
    ♥ Do have faith in what you're doing.