Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 9th May 2014, 08:09 PM   #1
Active Warrior
 
Join Date: 2012
Posts: 96
Thanks: 2
Thanked 30 Times in 21 Posts
Default
Making this exit pop JavaScript redirect immediately
Share on: 
fb share twitter share gplus share more share

Hello, I have this exit pop redirect Javascript. It works perfectly, except I want the page to redirect immediately while the prompt for the user to stay on page or leave is still there.

Does that make sense?

The script currently doesn't redirect until the user chooses to stay on page. But I have had one before that redirects immediately, even while the prompt is up.

Here is the script below. If anyone can help I would really appreciate it. Thanks.

<script language="javascript">
(function() {
setTimeout(function() {
var __redirect_to = 'http://myurl.com/';//

var _tags = ['button', 'input', 'a'], _els, _i, _i2;
for(_i in _tags) {
_els = document.getElementsByTagName(_tags[_i]);
for(_i2 in _els) {
if((_tags[_i] == 'input' && _els[_i2].type != 'button' && _els[_i2].type != 'submit' && _els[_i2].type != 'image') || _els[_i2].target == '_blank') continue;
_els[_i2].onclick = function() {window.onbeforeunload = function(){};}
}
}

window.onbeforeunload = function() {
setTimeout(function() {
window.onbeforeunload = function() {};
setTimeout(function() {
document.location.href = __redirect_to;
}, 500);
},5);
return '************************************** My Return Message ***************************';
}
}, 500);
})();
</script>

Want to Truly Lean How to Become a "Super Affiliate"? See How in This FREE Video Training. -> Click Here <-

A smart man knows his limits. A wise man knows he has none.

~Unknown
Technito is offline  
Unread 22nd May 2014, 08:07 AM   #2
Warrior Member
 
Join Date: 2014
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default
Re: Making this exit pop JavaScript redirect immediately
Share on: 
fb share twitter share gplus share more share

the settimeout() function you are using causes the delay because of the second argument you passed..decrease the 500 to 1 and it will work...besides, the script you wrote is redundant..try rewriting it in a simple way
samolabams is offline  
Unread 26th May 2014, 02:37 PM   #3
Active Warrior
 
Join Date: 2012
Posts: 96
Thanks: 2
Thanked 30 Times in 21 Posts
Default
Re: Making this exit pop JavaScript redirect immediately
Share on: 
fb share twitter share gplus share more share

Originally Posted by samolabams View Post

the settimeout() function you are using causes the delay because of the second argument you passed..decrease the 500 to 1 and it will work...besides, the script you wrote is redundant..try rewriting it in a simple way
Thanks for the response. But I actually didn't write the code, someone provided it to me without much instruction, and I am not really much of a coder.

I did however find the below script, which appears to be a much simpler script and does redirect immediately as I want it.

Code:
<script type="text/javascript" language="javascript">  var areYouReallySure = false; var internalLink = false; function areYouSure() { if (!areYouReallySure && !internalLink) { areYouReallySure = true; location.href="REDIRECT URL HERE"  return "* Message Here*"; } } window.onbeforeunload = areYouSure; </script>
But the problem is it pops up on any links that are clicked on my webpage rather than just when people exit off the page. After some research, I read that this code is missing something along the lines of:

onClick="dontpop();"
onSubmit="dontpop();"

If you or anyone else that's reading think you might know how I might add these lines into the script I would really appreciate it. Thanks.

Want to Truly Lean How to Become a "Super Affiliate"? See How in This FREE Video Training. -> Click Here <-

A smart man knows his limits. A wise man knows he has none.

~Unknown
Technito is offline  
Unread 26th May 2014, 05:32 PM   #4
Warrior Member
 
Join Date: 2014
Location: CA, USA
Posts: 10
Thanks: 2
Thanked 0 Times in 0 Posts
Default
Re: Making this exit pop JavaScript redirect immediately
Share on: 
fb share twitter share gplus share more share

This is not that difficult the second script you have put basically uses the "onbeforeunload" event. This is fired whenever the page is unloaded. This includes closing the browser tab and clicking on links that go to another URL. So the solution is to override this event for the anchor tags. This needs a little bit of work, I don't a ready code right now. In case you don't find a ready to use code, I will be happy to put together a script for you.

heslil is offline  
Unread 28th May 2014, 08:31 AM   #5
Active Warrior
 
Join Date: 2012
Posts: 96
Thanks: 2
Thanked 30 Times in 21 Posts
Default
Re: Making this exit pop JavaScript redirect immediately
Share on: 
fb share twitter share gplus share more share

Originally Posted by heslil View Post

This is not that difficult the second script you have put basically uses the "onbeforeunload" event. This is fired whenever the page is unloaded. This includes closing the browser tab and clicking on links that go to another URL. So the solution is to override this event for the anchor tags. This needs a little bit of work, I don't a ready code right now. In case you don't find a ready to use code, I will be happy to put together a script for you.
Yeah I know it's not really that difficult (especially for coders) but I don't know much about javascript at all, aside from copy/pasting codes and making minor tweaks within the code.

But I just want a script that will do just that and will work in all browsers. If you wouldn't mind putting together a simple script for me that will do that, I'll even pay you for it. But just let me know either way. Thanks.

Want to Truly Lean How to Become a "Super Affiliate"? See How in This FREE Video Training. -> Click Here <-

A smart man knows his limits. A wise man knows he has none.

~Unknown
Technito is offline  
Unread 28th Feb 2015, 01:49 AM   #6
Warrior Member
 
Join Date: 2015
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default
Re: Making this exit pop JavaScript redirect immediately
Share on: 
fb share twitter share gplus share more share

Originally Posted by samolabams View Post

the settimeout() function you are using causes the delay because of the second argument you passed..decrease the 500 to 1 and it will work...besides, the script you wrote is redundant..try rewriting it in a simple way
Check this ......Javascript Redirect

Lee
bikithalee is offline  
Unread 4th Jun 2015, 08:46 AM   #7
Warrior Member
 
Join Date: 2015
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default
Re: Making this exit pop JavaScript redirect immediately
Share on: 
fb share twitter share gplus share more share

I was able to succesfully implement the javascript on a page on my website BUT the text on the text in the popup in Firefox says "This page is asking you to confirm that you want to leave - data you have entered may not be saved." But that is not the text that I set in my script.

It works correctly in all other browsers.

Any suggestions on how to get it to function correctly in FF?
cwalsh is offline  
Closed Thread


Bookmarks

Tags
exit, immediately, javascript, making, pop, redirect


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 12:00 PM.