StatCounter User Forum  
StatCounter Free web tracker and counter

Go Back   StatCounter User Forum > Webmaster > Lounge (non-StatCounter related topics here!)

Closed Thread
 
Thread Tools Display Modes
  #1  
Old 11-21-2006, 03:55 PM
webado's Avatar
webado webado is offline
Moderator
 
Join Date: Apr 2004
Location: Montreal, Quebec, Canada
Posts: 28,145
Default How to replace target="_blank" for XHTML strict w3 compliance

There are those proponents of opening links (especially external ones) in a new window and then the a purists who think it's an abominaiton

For those who prefer the ability to open links in a new window yet keep a valid XHTML strict doctype, I stumbled onto an elegant piece of code that will allow just that.

Instead of using target="_blank" on a link, use rel="external" and then have javascript that performs a little miracle.

Plainly put if the visitor's browser is javscript enabled the link with rel="external" will behave like target="_blank", otherwise it's inert.

See it here: http://www.sitepoint.com/article/sta...pliant-world/3



The only other little problem to solve is to be able to specify both rel="external" and rel="nofollow" - maybe like rel="external nofollow" together.
I haven't looked at what if any javascript changes need to be done to allow this.

I am currently using this method for all external links on www.webado.net which I have converted to xhtml strict lately and it works like a charm.
__________________
Christina
>>Forum Moderator<<

Please do not PM me for support. The forum is here for that.
  #2  
Old 11-21-2006, 04:09 PM
JWJ JWJ is offline
Moderator
 
Join Date: Jan 2004
Location: England
Posts: 5,692
Default

I know I'm stepping out of my league here but I feel I must comment on this. Surely, coding to the highest level possible is a 'purist' activity and therefore using target=_blank is a bit of a contradiction. Rather than code to 'strict' levels and then concoct a work-around for something you're not supposed to do, wouldn't it be better to code to 'transitional' level and use target_blank in the conventional manner?
__________________
... John ...

Last edited by JWJ; 11-21-2006 at 04:33 PM.
  #3  
Old 11-21-2006, 04:52 PM
webado's Avatar
webado webado is offline
Moderator
 
Join Date: Apr 2004
Location: Montreal, Quebec, Canada
Posts: 28,145
Default

Well yes and no.

The "purist" idea is in my opinion a possibly wrong interpretation of the purpose this standard is meant to have.

I believe it's essentially in order to help robtos crawl better since sending them off here and there with target="_blank" may be somewheat counterproductive.

Other purists may have taken it to mean let user decide if a link is a new window or not - well ok, but I and possibly countless others don't go around right clicking links so that we get to pick new or same. It bugs me no end when I go to an external link and by pure force of habit I close the window after seeing it's not on the same site - and then I've ended up closing the whole thing.

Anyway, it's to take or to leave.

I will always open external links in new windows - and that's that.

Now that I went through the exercise of converting to xhtml strict (which may have benefits other than just academic, but yet to be discovered by yours truly) I don't intend to change that habit

So this is a valuable workaround for me and for anybody who wants the same thing.

It can also be used in all other doctypes to accomplish the same thing. Robots will have a nice smooth crawl with no new windows and users will have the navigation I intend for them to have - whether they like it or not It's part of my designs, so if they don't like it, tough

Oh and I did manage to modify the script to allow rel="nofollow external" and "rel="external nofollow" as well.

So my script called external.js is now:

Quote:
function externalLinks() {

if (!document.getElementsByTagName) return;

var anchors = document.getElementsByTagName("a");
for (var i=0; i<anchors.length; i++) {
var anchor = anchors[i];
var relvalue = anchor.getAttribute("rel");

if (anchor.getAttribute("href")) {
var external = /external/;
var relvalue = anchor.getAttribute("rel");
if (external.test(relvalue)) { anchor.target = "_blank"; }
}
}
}
window.onload = externalLinks;
__________________
Christina
>>Forum Moderator<<

Please do not PM me for support. The forum is here for that.

Last edited by webado; 11-21-2006 at 04:55 PM.
  #4  
Old 11-21-2006, 05:19 PM
JWJ JWJ is offline
Moderator
 
Join Date: Jan 2004
Location: England
Posts: 5,692
Default

Thanks for sharing your thoughts on that.

When I was converting some pages to strict I came across this very problem. In one case I decided to go strict and dispense with the new window, in another case I decided I wanted the new window so I left the page as transitional. As far as I'm concerned 'strict' is 'strict' and 'strict' with a bit of a workaround is less than 'strict'.

Of course, my approach is also a work-around .... it works around the fact that I don't know javascript.
__________________
... John ...

Last edited by JWJ; 11-21-2006 at 05:33 PM.
  #5  
Old 11-21-2006, 07:48 PM
webado's Avatar
webado webado is offline
Moderator
 
Join Date: Apr 2004
Location: Montreal, Quebec, Canada
Posts: 28,145
Default

Quote:
Originally Posted by JWJ
Of course, my approach is also a work-around .... it works around the fact that I don't know javascript.
Neither do I but I can bluff may way around a bit

Just you wait, I'm working on making colored scrollbars that even the w3c will accept - or rather ignore blissfully
__________________
Christina
>>Forum Moderator<<

Please do not PM me for support. The forum is here for that.
  #6  
Old 11-22-2006, 11:58 AM
coombes coombes is offline
Member
 
Join Date: Apr 2005
Posts: 116
Default

Purism for me is a site that works, looks right on very browser and does what's expected of it. If I get what I want but it isn't 100% valid... the site still works.
  #7  
Old 11-22-2006, 02:09 PM
-=Seth=- -=Seth=- is offline
Active Member
 
Join Date: Nov 2006
Location: lost in space
Posts: 516
Default

Quote:
coloured scrollbars that even the w3c will accept
that would definately be cool
  #8  
Old 11-22-2006, 03:42 PM
webado's Avatar
webado webado is offline
Moderator
 
Join Date: Apr 2004
Location: Montreal, Quebec, Canada
Posts: 28,145
Default

Quote:
Originally Posted by coombes
Purism for me is a site that works, looks right on very browser and does what's expected of it. If I get what I want but it isn't 100% valid... the site still works.
Heh, it works in all browsers (at least non-mac stuff), you get what I want you to get out of it and it is 100% valid too - how's that for purity?
__________________
Christina
>>Forum Moderator<<

Please do not PM me for support. The forum is here for that.
  #9  
Old 02-03-2007, 05:32 PM
SLORider SLORider is offline
Junior Member
 
Join Date: Feb 2007
Location: San Luis Obispo, CA USA
Posts: 1
Default

I really don't see the point in serving "supposedly valid" XHTML, then making it invalid via JavaScript. In fact, I avoid script like the plague as you never know if it's enabled on the client or not.

If you modify the DOM after the page is served, your page is still not valid XHTML. If browsers ever start enforcing the XML DTDs you'll see this. I think it's just fooling yourself by thinking passing the W3C Validator is the gold standard.

I don't see the point of robots having a "smooth crawl". They probably don't even look at target="_blank". If they do, it's a good hint the link is external.

On the other hand, I like target="_blank" and use it for external links. I'm trying to supply an external link icon which I think is the best etiquette if you're going to use target="_blank".
  #10  
Old 02-03-2007, 09:18 PM
jukcoder jukcoder is offline
Member
 
Join Date: Oct 2006
Location: Birmingham,UK
Posts: 252
Default

I was to use this trick till I decided to remove all popups in my web site. If I am refererring to an external URL I have to add a pop-icon to the link : humans and search engines won't have the right to complain.
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:06 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.