0

We'd like to have a message popup when a visitor to specific webpages leave those webpages. So we could tie some Javascript to the links on those webpages, but then we can't control if the user exited the webpage by typing in a URL, using a bookmark or just closing the window...

I assume we have limited options if the user tries closing the browser window... but I do know it's possible because Google Docs' Documents offers the chance to cancel closing the window if you have unsaved work while closing the browser.

What are my options? Can I have Javascript called upon going to another webpage? Can I control the text in the popup when trying to close the window?

I'm using jQuery, so if there are good solutions implemented with jQuery that's perfectly fine.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
at.
  • 50,922
  • 104
  • 292
  • 461
  • 1
    Unless its for functional reasons (e.g. Google Doc's saving changes to the active document), I would be against this anyway, its bad UX design...you're introducing an unexpected behaviour when the user is expecting a specific result (e.g. Close). Plus, it's really annoying... – Matthew Abbott Jan 08 '11 at 11:10
  • Thank you for your opinion, I agree with you – at. Jan 10 '11 at 01:46
  • Does this answer your question? [jQuery UI Dialog OnBeforeUnload](https://stackoverflow.com/questions/1889404/jquery-ui-dialog-onbeforeunload) – Brian Tompsett - 汤莱恩 Sep 26 '20 at 11:00

2 Answers2

0

There is onunload event you can bind to, first example:

http://www.codetoad.com/javascript/miscellaneous/onunload_event.asp

cji
  • 6,635
  • 2
  • 20
  • 16
0

Yes.

https://developer.mozilla.org/en/DOM/window.onbeforeunload

jQuery UI Dialog OnBeforeUnload

Community
  • 1
  • 1
Dean Burge
  • 3,440
  • 25
  • 22