View Full Version : Creating a simple exit page?
Morgan19
04-20-2006, 11:09 AM
I'm working on a site on which they'd like a user to go to a "Thank you for visiting, you are now leaving our site" page when that user clicks on an external link. After seeing the page for a couple seconds, it would then forward them along to the external link's page they'd clicked on.
I've researched this a bit and found a way to do it in ASP but I'm wondering if there's some way to code it in Javascript or plain HTML? (The site is very basic– plain .shtml with no bells and whistles, so the solution needs to be simple as well.) I've used redirect pages before but this is a bit trickier as I need one forwarding page for all the external links (about 50 total) so I'd rather not manually make 50 redirect pages... I've found a Javascript code to pop up a YES/NO window for leaving to an external link, but if we go that route I just need it to say "You're leaving blah blah," and then an "OK" button after which the user would go to the external page.
I understand the stigma against these sort of things but unfortunately the client is insistant. In this particular case there's no survey or statistics attached– they just want to make sure people know they're going elsewhere (as if seeing a whole new page design wasn't enough...).
Thanks,
m19
hammerstein_04
04-20-2006, 11:16 AM
what about passing the URL to the redirect page as a get var, then extracting it using javascript.. then wait x seconds and then set the page target to be the url?
I'm not experienced in things like that..so apologies if that is a really unacceptable solution.
Morgan19
04-20-2006, 11:18 AM
what about passing the URL to the redirect page as a get var, then extracting it using javascript.. then wait x seconds and then set the page target to be the url?
Can you (or anyone else) translate that? :) I understand what you're saying, but I'm just not sure how to actually code that into the link.
m19
hammerstein_04
04-20-2006, 11:32 AM
Link would look like;
http://www.mysite.com/refer.html?to=http://www.somebody.com
When you click the link it will send to refer.html. This would be your, thank-you for visiting our site. Then you could strip the to var out using javascript. Wait 5 seconds, then using javascript set the page location to be the new url.
I am not 100% on that, so don't take this is either a valid or good method, but that's the first way I would have tried it.
Piperwolf
04-20-2006, 11:48 AM
Honestly, morgan, i think that's a good idea and don't see anything wrong with it as long as it works (self close being the import part or self redirect, having the user click something addtional, even an "Ok" would make it annoying). I'm going to look at Hammer's idea there then see if there's a better way.
Morgan19
04-20-2006, 11:49 AM
Thanks for your patience! This is the part I'm not familiar with:
Then you could strip the to var out using javascript. Wait 5 seconds, then using javascript set the page location to be the new url.
I know you said you're not sure on this, but I might need a bit more hand-holding, either from you or someone else. Could someone be kind enough to spell out the coding I need to do? I've tried researching the various things you've said and am not having much luck on how to actually set up that bit of code.
Thanks agian,
m19
hammerstein_04
04-20-2006, 11:58 AM
http://www.activsoftware.com/code_samples/code.cfm/CodeID/59/JavaScript/Get_Query_String_variables_in_JavaScript
That gives you an idea on how to retrieve the get var from the URL.
Then sleep(5) ? is that the Javascript command? I use JS so rarely. Then
document.location = theUrlImGoingTo;
and it should redirect.
I'm at work or I would be trying to play around with this myself, see if it is even feasible.
_Aerospace_Eng_
04-20-2006, 01:39 PM
Here is my 2cents on this. No need to alert them because they KNOW they are leaving the site once they click a link. The alert will come up and say you are leaving. So? Its not like your alert allows them to stay on your sight.
Morgan19
04-20-2006, 01:40 PM
Here is my 2cents on this. No need to alert them because they KNOW they are leaving the site once they click a link. The alert will come up and say you are leaving. So? Its not like your alert allows them to stay on your sight.
Not really sure what you're saying. Like I said, this is a request on the client's behalf. I'ts not my call whether or not there's an alert– there needs to be one, period.
m19
_Aerospace_Eng_
04-20-2006, 01:45 PM
At some point in time the client needs to be corrected but its your call on whether you want to do that or not. I just think an alert telling the user they are leaving is a waste of the users time. Do the external links open up in new windows or the same page?
Morgan19
04-20-2006, 01:49 PM
Trust me, we've tried. I understand where you're coming from but you're preaching to the choir, and whether an alert should or shouldn't be made wasn't the point of my making this thread. Thanks for your concern, though.
m19
_Aerospace_Eng_
04-20-2006, 01:51 PM
Answer my last question. How are the external links being opened? Same page or new window?
Morgan19
04-20-2006, 01:54 PM
(Tactful, aren't we?)
They'll be opening in the same window. Now I sincerely hope you're asking for the sake of helping me and not another "you shouldn't do this", because I've already said my peace on that bit and it doesn't need to muck up this thread any more.
m19
_Aerospace_Eng_
04-20-2006, 02:14 PM
I wouldn't ask if I wasn't going to help.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script type="text/javascript">
function setAlert()
{
var theLinks = document.getElementsByTagName("a");
for(var i = 0; i < theLinks.length; i++)
{
if(theLinks[i].href.search("http:") == 0)
{
theLinks[i].onclick = function()
{
alert('You are now leaving the page.');
}
}
}
}
onload = setAlert;
</script>
</head>
<body>
<a href="http://www.yahoo.com">Yahoo</a>
<a href="#">local</a>
<a href="http://www.google.com">Google</a>
<a href="notgoinganywhere.html">No where</a>
</body>
</html>
Morgan19
04-20-2006, 02:26 PM
Thanks for whipping that up, I really appreciate it. That being said, I'm curious about something else– I've looked through the code and can't figure it out, but currently the code seems to pop up the message no matter where the links go. In other words, even the anchor links are internal site links give me the message. But the original intent was to have a message pop up when a user leaves the *site*, not just the page. For example, if I were to click on a link here at HTMLforum.com to go to Google, I should get the message– but not if I just click a link to go elsewhere on this site.
m19
Piperwolf
04-20-2006, 02:27 PM
I had a bit of a different solution than aero. your main page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">
<head>
<title> On link, open 2 windows one on a close timer, close self after </title>
<script type="text/javascript">
function exitfunction(refurl,timer) {
window.open(refurl,"referredwebsite");
window.open("exitpage.html","exitpage");
window.focus("exitpage");
window.close();
}
</script>
</head>
<body id="mybody" name="mybody">
<a href="#" onclick="exitfunction('http://www.google.com',6000)">www.google.com</a>
</body>
</html>
Your exit page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">
<head>
<title> Thanks For Visiting! </title>
</head>
<body onload="setTimeout('window.close()',5000)">
<p>Thanks for visiting!</p>
<script type="text/javascript">
window.focus(); //get focus
</script>
</body>
</html>
There may be an easier way to do this, but whenever I pull up a page on my computer here, it likes to block the javascript with a little blip at the top, so I had a hard time testing the focus part of the script (whats the use of the exit page if google takes focus and the exit page is in the background?)
edit: prompts me to confirm ("Trying to close this page, is that alright?") only on the main page... Let me twiddle around with it, I think I figured out why it wasn't allowing javascript on my html that was coming from my own computer so now I don't have to open a new window for google.
_Aerospace_Eng_
04-20-2006, 02:31 PM
As far as all of the links having the alert, that means all of your links are absolute meaning they all have http:// in them. I was assuming your links were relative but apparently they aren't. Try this
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script type="text/javascript">
function setAlert()
{
var yourURL = "http://www.yoursite.com" //change this to match your own site
var theLinks = document.getElementsByTagName("a");
for(var i = 0; i < theLinks.length; i++)
{
if(theLinks[i].href.search(yourURL) == -1 && theLinks[i].href.search("http:") == 0)
{
theLinks[i].onclick = function()
{
alert('You are now leaving the page.');
}
}
}
}
onload = setAlert;
</script>
</head>
<body>
<a href="http://www.yahoo.com">Yahoo</a>
<a href="http://www.yoursite.com/#">local</a>
<a href="http://www.google.com">Google</a>
<a href="http://www.yoursite.com/notgoinganywhere.html">No where</a>
</body>
</html>
Be sure to change yourURL to match your sites url. Basically the script searches the href of all the links 1 at a time. If it doesn't find your url in there it returns -1. If it finds the string you were searching for it returns 0 so checking for your url in all of the hrefs will return -1 if the href doesn't contain your url and to be sure its an external link I also search for http: inside of the href so any link that doesn't have your url in and doesn't have http in it will still not have the alert because its assumed its a link on your own site.
Morgan19
04-20-2006, 02:49 PM
Excellent! I tried your first version again– my local site links *are* relative, but for some reason when I copied/pasted your code the first time it was popping up on each one. I tried it again and everything's working fantastically.
Thank you again, everyone, for your help– this was a lifesaver. :)
m19
Morgan19
04-21-2006, 11:45 AM
I take that back, it's not working right. (I'm using relative and absolute links where appropriate.) Using the first version of the code you gave me, it appears that the code works fine when I test it locally but as soon as I upload it to the server and test it online it gives the popup message for every single link, no mater if it's relative or absolute.
m19
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.