search

Home  >  Q&A  >  body text

javascript - Why can the sessionStorage be saved when the onbeforeunload prompt box is closed and refreshed, but the alert cannot be played?

http://www.runoob.com/jsref/e...

After hooking up.
Refresh it again
The function body will not be triggered at all.
I tested it. Why is this?
Just leave it unchecked

window.addEventListener("beforeunload", function(event) {
    alert("弹出");
    sessionStorage.name="你的名字";  //请教一下为什么这个sessionStorage都能存下来?而alert没弹出来?这是什么机制啊? 
});

http://jsbin.com/zisazacani/e... JS Bin online example

滿天的星座滿天的星座2840 days ago907

reply all(1)I'll reply

  • 世界只因有你

    世界只因有你2017-05-19 10:32:57

    Thanks for the invitation

    Official documentation explains

    Starting from May 25, 2011, the HTML5 specification states that in this event handler, calls to window.alert(), window.confirm(), and
    window.prompt() will be ignored. See the HTML5 specification for details.

    In addition, this is for security reasons and does not allow disabling system pop-ups.

    reply
    0
  • Cancelreply