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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Alert message for external links 1

Status
Not open for further replies.

daph

Programmer
Jun 9, 2000
65
CA
Hey everyone,

I'm working on this web site where most of the pages are on my server, but some of the links on these pages brings the user to external pages - pages that aren't mine. I would like to have a message informing the user that the destination is no longer on my web site as they click on the link. I know I can do this with "onClick" for every link that are external, but I have so many pages and I'm sure there's another way, an easier way to do this. Isn't there a way to check the domain names in my links for every page instead? Some kind of a search when the page loads or unloads? If someone has an idea, that would be great!

Thank you guys! :)

PS - If something isn't clear, just ask. I'll try to be more precise.
 
what browsers are you supporting? jared@aauser.com
 
I'm working with: Internet Explore 5
 
make sure you're local hrefs do not include " in them, then you can use:

function externalLinkHandler()
{
var el = window.event.srcElement;
if(el.tagName=="A")
{
if(el.href.indexOf(" {
alert("You are connecting to an external site.")
}
}
}
document.onclick=externalLinkHandler jared@aauser.com
 
Ok, I'll will try that...just curious though..is there a way to verify if the domain name is the same? For exemple, if a page isn't on my server, but is still from the same company or organization - is there a way to find out if the link is from the same company even if it is external?

Thank you so much for your help, I appreciate this.
daph
:)
 
if all the links contain the full path (including a domain name), you could use the same method, i.e. indexOf() to find out if a link is in a certain domain, just pass in the domain you are looking for like: indexOf(domain) ray
rheindl@bju.edu

 
Where does the document.onclick=externalLinkHandler go? In <BODY> or <HEAD>? I have some errors...

daph
 
stick it in the head, but after the function definition.
You could always change the if statement to say:

if(el.href.indexOf(&quot;yourdomain.com&quot;)<0))

to see if the href does NOT contain your domain

i noticed their is a semicolon inserted after the indexof statement in my original code post... this site added that, just replace it with a ')' jared@aauser.com
 
Well, I'm having some syntax problems...but I'll work on it. Thanks again!

daph
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top