[Javascript] Alert user when leaving site

Triche Osborne wdlists at triche-osborne.com
Sat Sep 10 16:47:58 CDT 2005


Julien Nadeau wrote:
> What has  
> to be done is try to compare this string to the destination domain. I  
> have no idea how to do this automatically, but you could modify my  
> function to add it to every link in the page and add an destURL  
> argument to compare (this could be done automatically by scanning the  
> DOM for every <a> element and adding events to each of theses).
> 
Another thought on this: Use an onload event (similar to those used for 
Suckerfish menus) to loop through all of a page's links and add an 
onclick event which passes this.hostname to a function which compares 
the link hostname to the current domain name. If they are the same, do 
nothing; if not, issue the alert. The alert will halt the transfer until 
cleared. Since the onclick event takes precedence over the link 
activation, you can eliminate the unload event.

Triche




More information about the Javascript mailing list