Forum Moderators: not2easy

Message Too Old, No Replies

External Hyperlink Targeting Using CSS

setting the external hyperlinks target in the style sheet

         

Dreamdesigner

9:04 pm on Mar 16, 2006 (gmt 0)

10+ Year Member



I am new to this forum and relatively new to CSS.
I am attempting to find a way to specify the target attribute of specified external hyperlinks in the style sheet on an Xhtml 1.0 strict page, but cannot find a syntax that will work. I can use the onclick attribute in the html code of every individual link, which works fine, but is very time consuming when coding the pages. Also how would I create an alert to the user that they will be leaving my site.
Is there a solution using CSS?
Any help would be greatly appreciated.

coopersita

9:27 pm on Mar 16, 2006 (gmt 0)

10+ Year Member



CSS is intended for formatting only. The target information should be html or javascript.

Imagine if your css didn't load, then your links wouldn't work properly.

Dreamdesigner

9:37 pm on Mar 16, 2006 (gmt 0)

10+ Year Member



Thanks for the info. After doing much investigating into this I guess that it would be better just to use the onclick event attribute using html but I still need a way to alert the user that they are leaving my site can I do this in a javascript function?

bedlam

9:53 pm on Mar 16, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



but I still need a way to alert the user that they are leaving my site can I do this in a javascript function?

A client recently had me build a widget like this--over my strong objections--and I fully expect the client to notify me that they'd rather not use the script anymore after a couple of months' worth of user complaints. Don't do it.

Having said that, it's easy enough. You're just going to have to do the following (in pseudo-code):

  1. Use getElementsByTagName('a') to collect all of the links in the page
  2. Loop through all of them and check to see if the href attribute contains your domain name
  3. for those links that don't, disable the link and set an onclick event calling your 'linkus interruptus' function
  4. Use that function to popup a dialogue box when the external links are clicked

Again though I think this is a very bad method for notifying the user of something that they, in all probability, already know. A far better method would be to use the same method (collecting together and checking the href attributes of every link) do something like what wikipedia does with their external links--use css to display a little icon beside the link text.

-b