3

I want to add an additional function to a basic plain javascript exit page popup. Basically, I have my page set up so when a user tries to exit the page a message will appear saying "do you really want to leave" with the options "OK" and "Cancel". I want to set it up so when the user clicks OK it will redirect them to another website. I don't have a lot of experience coding so I'm not sure if this is possible. Here is the code that I'm using:

<h1 id="home">Warn before leaving the page</h1>

<script>
// Warning before leaving the page (back button, or outgoinglink)
window.onbeforeunload = function() {
   return "Do you really want to leave?";
   //if we return nothing here (just calling return;) then there will be no pop-up question at all
   //return;
};
</script>

<a href="http://google.com/</a>

Any help will be appreciated, Thanks!

1 Answers1

0

This is something you should avoid doing because it is bad user experience. Also this is a repeat of this post.

miozzz
  • 113
  • 6
  • I won't be using it in a published website, I just want to experiment with it. Also the post you linked is showing how to code the exit warning but I want to know if I can get it so the code opens up another webpage on exit. – The Neurocartographer Sep 25 '18 at 13:19