Ok, I'm trying to tweak some JS code that will open a popup when the visitor tries to exit the page. When the user tries to exit the page they get a popup however at the same time I'd like the page behind the popup to automatically redirect to a specified URL. Any suggestions please? <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> function PopIt() { return "Are you sure you want to leave?"; } function UnPopIt() { /* nothing to return */ } $(document).ready(function() { window.onbeforeunload = PopIt; $("a").click(function(){ window.onbeforeunload = UnPopIt; }); }); </script> Code (markup):
<script type="text/javascript"> function PopIt { alert("Are you sure you want to leave?"); window.location = "Redirect URL Here"; } $(document).ready(function() { window.onbeforeunload = PopIt; } </script> Code (markup): This should work but I'm rather tired so maybe not.
may be you can try using .unload() of jquery.... You'll have to use a older version of jquery though (<1.8)... I don't think it'll work, but worth a try...
I don't think that you can do this. If the user wants to leave they will leave. You can set a message to confirm they want to leave but not redirect them.
This is definitely possible with a llittle tweak in the code uploaded by you. The message can definitely be set but redirecting them to the respective page as defined certainly needs a good hand at programming.
Which programming would accomplish this? I'm sure browsers do not allow you to redirect a user when they try to leave.