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

check external link and display div

Status
Not open for further replies.

derwent

Programmer
May 5, 2004
428
GB
Can someone help, I am wanting to have a javascript check for an external link and if it is then display a div to say it is an external link.

An example is if you scroll down and click a book for sale. thanks
 
What do you mean check for an external link?
Are you trying to validate an href the client provides to see if it is at a different location or are you actually trying to validate whether the link specified actually exists?


At my age I still learn something new every day, but I forget two others.
 
sorry, my original post was a little vague reading it back.

Basically if there is an external link on my site (so the user opens up a webpage that isn`t mine) I want a div to pop onto the screen to say you are leaving my site, it is an external link etc etc.

Inside the div it will give two links, 'do not leave my site' which will close the div and stay on my page and 'go ahead and leave' which will open up the external webpage.

Accessibility wise I can`t use onclick so I guess I can use ID tags wityhin the <a> tag?
 
You could use the onunload event that pops up a message whenever the person leaves your site.

It seems really obnoxious to me though every time I navigate away from a site only to have it ask if I REALLY wanted to leave. It's like telling the person they would be stupid to go anywhere else and making them confirm they want to continue being stupid.

That said, another alternative is just to have any external links on your page open to another browser window. Just add target="_blank" to your href and that link will open in a new window rather than changing the one they are currently on.
Ex: <a href=" target="_blank">Go somewhere</a>


At my age I still learn something new every day, but I forget two others.
 
I have open blank at the moment but every now and again I receive emails saying that my site isn`t working, when I ask for the url of the offending page it is an external website! Believe it or not one of those emails was from my IT manager! I guess I just have really stupid users.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top