i need to display confirm dialog box before close browser window using javascript or PHP. the confirm box should come when i click the close button of browser. other wise don't display dialog. please help me any.
标签:
javascript
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
onunload
is not very useful (in my opinion) as you can't do anything with theconfirm
ation you're requesting (except maybe attempt to new another window withwindow.open
, soonbeforeunload
is more useful for this case.Your better bet is
onbeforeunload
, which is great but won't work in Opera (though this usually isn't a deal breaker).Like ivy said, it would look something like this:
You should handle the onbeforeunload event...
Or use jquery, window.attachEvent / window.addEventListener to do it nicely