search

Home  >  Q&A  >  body text

javascript - Why does window.onbeforeunload have console.log() not appear on the browser console?

window.onbeforeunload=function(){
  console.log("为啥不能运行");//这个为什么不出现控制台呢?
   return ;
}
我想大声告诉你我想大声告诉你2858 days ago471

reply all(2)I'll reply

  • 黄舟

    黄舟2017-05-19 10:34:10

    window.onbeforeunload=function(e){
      e.returnValue = 'something'
      console.log("为啥不能运行");
      return ;
    }

    You must bind a value to the returnValue attribute of the event, otherwise the browser will be closed directly and you will not be able to see the console output

    reply
    0
  • 世界只因有你

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

    <body onbeforeunload="return ''">
    
    http://www.runoob.com/jsref/event-onbeforeunload.html
     

    reply
    0
  • Cancelreply