To absolutely ensure maximum accessibility for your users, your website mark-up should be valid to the W3 guidelines. Using WordPress and multitudes of plugins that inject further code into your source can make that all very difficult.
I’ve spent this evening digging through my siderbar.php and header.php trying to locate everything that the W3 validator had picked up on. Finally I was left with the all-too-common target=”_blank” debate. This was depreciated some time ago because the website visitor should be able to dictate that sort of behaviour from their browser rather than the developer, but I would far prefer that people didn’t lose my website altogether if they click a link out for a while.
The point of this post isn’t to debate whether this though, it’s to brag that I managed to make at least one page on this site validate and still include target=”_blank”.
Of course it’s very likely that by the time you read this it’ll no longer be valid again, but I’ll enjoy my glory whilst it lasts – such is the nature of an ever-evolving web blog.
The fix was a simple one-liner in my (document).ready declaration :
$("a[href*='http://']:not([href*='"+location.hostname+"'])")
.attr("target","_blank");
And all it does is detect links that start with http:// that don’t link back to your own domain, and then appends the target back into the link. Schimples.
Now I just have to go back through all my old posts and remove all the tags…!
Comic unceremoniously stolen from the very amusing gentleman over at xkcd.com with thanks
No Responses to “XHTML Strict and target=”_blank” with JQuery”