Exit Redirect

trevormorley

Regular Member
Joined
Feb 25, 2010
Messages
250
Reaction score
88
Can anybody tell me if there is a wp plugin or methos whereby on leaving my page that the user is redirected to another one - I currently use exitwindow but it is easy for the user to click on the pop up and cancel the redirect, I don't want them to have the choice, I just want it to take them there...
 
I am looking for the samething for wordpress but couldn't find it anywhare??
 
It seems like there is no way to avoid the option. I have found the following comment

"You actually can't, directly. The browser takes charge of showing the confirmation, and either continuing the navigation if OK, or doing nothing if Cancel. You don't get to find out whether the user clicked OK until you get the final unload, by which point it's too late."

A simple code (including the option) that worked for me is:
<script type="text/javascript">
window.onbeforeunload = function (evt) {
var message = 'Are you sure you want to leave?';
if (typeof evt == 'undefined') {
evt = window.event;
}
if (evt) {
evt.returnValue = message;
window.location = "yourURLhere";
}
return message;
}
</script>
 
I know this is an old thread but I just found it and tried
I pasted the script into the header and it works but I still get the
window "This page is asking if you want to leave"

is there a way to force the redirect without getting the window?

thx
 
I know this is an old thread but I just found it and tried
I pasted the script into the header and it works but I still get the
window "This page is asking if you want to leave"

is there a way to force the redirect without getting the window?

thx

I think it's a security feature in the browsers.. it's not the actual code or plugin popping this up.. but when the code does try to redirect them.. the browser pops up that menu as a security feature.. otherwise you could just keep redirecting them until they closed out the browser.. which is malicious
 
A member here produced a plug in called Bounce Rate. Search the forum for the thread. I haven't tried it yet so YMMV.
 
There is one called exit rescue. It does give the option for user to stay or leave but it will automatically try to load whatever site you want in the background. Not sure if that's what your looking for?
 
It seems like there is no way to avoid the option. I have found the following comment

"You actually can't, directly. The browser takes charge of showing the confirmation, and either continuing the navigation if OK, or doing nothing if Cancel. You don't get to find out whether the user clicked OK until you get the final unload, by which point it's too late."

A simple code (including the option) that worked for me is:
<script type="text/javascript">
window.onbeforeunload = function (evt) {
var message = 'Are you sure you want to leave?';
if (typeof evt == 'undefined') {
evt = window.event;
}
if (evt) {
evt.returnValue = message;
window.location = "yourURLhere";
}
return message;
}
</script>
HI,
It show the message but not redirect to the website, what's wrong with wordpress 3.9.1?
 
Thanks akleinesw for this. but my problem is,the current settings shows the message ,when i try to view the internal pages or external pages.
My requirement is simple,the page will shows/redirect only if the visitor try to close the window ,but if they visit other external or internal pages of web site means it shouldn't show the message or redirects.

Thanks in advance
 
Last edited:
I have the perfect solution for you. Check out BackJacker and stop giving users the option to leave or stay and send them wherever you want when they click the back button.
 
Back
Top