Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript URL Sniffing in lieu of OnUnload event

Status
Not open for further replies.

toaster

Programmer
Apr 10, 2001
2
US
Hi.
I'm trying to develop a way that I can redirect the browser to a friendly "goodbye" page when they leave the site, but I want it to be based on entering a URL from a source other than my server.
I have tried using the OnUload tactic and it seems to fire prematurely (when returning to the main page from sub pages or reloading).I only want it to fire when the source URL for the page they're going to is located elswhere.
Any ideas?

Thanks, B-)
-Toaster
 
This will do what you need it to do. Any browser that has the onUnload event will be able to process the href="javascript:" method. There would also be a way to scan a string for whatever but this is *a lot* easier and quicker.

Hope it helps,
Rob

Code:
<html>
<head>
<script>
 function SayGoodbyeGracie(site,mode){
  if (mode==1){
   alert(&quot;Goodbye Gracie&quot;);
  }
  window.navigate(site);
 }
</script>
</head>
<body>
 <a href=&quot;javascript:SayGoodbyeGracie('thissite.html',0)&quot;>Go to page within this site</a>
 <br>
 <a href=&quot;javascript:SayGoodbyeGracie('[URL unfurl="true"]http://www.anothersite.com/',1)&quot;>Go[/URL] to page at another site</a>
</body>
</html>
[sig][/sig]
 
This is helpful, but I can't tell from looking at the solution if it will have an impact in cases of users clicking reload, or entering a URL from the Browser's address box.

Idealy the process I imagine should go something like this: When the unload event occurs, the function is then called, it checks the new url against the host url ( and if the new page is a subset of the host URL it does nothing, however if the new page is outside that domain, it will then fire and make a pop up window.

I admit that I really need to take some Javascript classes, it's just fitting in the time with my real job.
 
No, actually it isn't a help as it only works
when you click on a link, not when they type the url in the window

I, along with the poster, would love ot know if you can tell somebody is leaving the url *only, as he requested, by typing the url&quot;

the link is a problem 'cause not everybody wants to add the
a href=&quot;javascript:SayGoodbyeGracie

to each link

It's a very good script, but not the solution, which is ok. I have yet to see it, that's why even I asked about it and am searching the archives. Is it possible to do?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top