onbeforeunload support detection

前端 未结 10 1146
慢半拍i
慢半拍i 2020-11-28 11:21

I\'d like to check if the current browser supports the onbeforeunload event. The common javascript way to do this does not seem to work:

if (window.onbeforeu         


        
10条回答
  •  时光取名叫无心
    2020-11-28 11:44

    It would probably be better to just find out by hand which browsers support it and then have your conditional more like:

    if( $.browser.msie ) {
      alert( 'no' );
    }
    

    ...etc.

    The $.browser.msie is jQuery syntax, most frameworks have similar built-in functions since they use them so much internally. If you aren't using a framework then I'd suggest just taking a look at jQuery's implementation of those functions.

提交回复
热议问题