By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,598 Members | 1,897 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,598 IT Pros & Developers. It's quick & easy.

Create Javascript alerts

P: 40
My requirement is to display, via an overlay, a message informing the user they are leaving and allow them to continue or cancel. This will only occur if the user is leaving the site to go to an external site.

There are links to other websites in my website. Whenver a user navigates away from my website, a alert has to be displayed.

Is there any better option or sample code to do that.
Jul 30 '08 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 15k+
P: 16,027
Use onbeforeunload, e.g.
Expand|Select|Wrap|Line Numbers
  1. window.onbeforeunload = displayConfirm;
  2. function displayConfirm() {
  3.   return "Are you sure that you wish to navigate away?";
  4. }
Use it wisely otherwise it can be annoying.
Jul 30 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.