No one logged in. Log in

Replacing the XHTML deprecated <a target="_blank"> tag

Patrick Steil - Wednesday, February 16, 2011
The <a target=_blank> tag was deprecated in the XHTML specs and some validators will complain if you include this tag in your HTML. Here is a great way to
  • open the link in a new window (for users with javascript enabled)
  • allow opening the link with the keyboard (spacebar) (for users with javascript enabled)
  • open the link in the same window for non-javascript users (so we still fallback to a working link)
  • passing XHTML validation

Old Method Sample Link 

 <a href="http://www.infranet.com" target="_blank">Old Method Sample Code</a>
 

New Method Sample Link

<a href="http://www.infranet.com"
onclick="window.open(this.href); return false;"
onkeypress="window.open(this.href); return false;">New Method Sample Link</a> 
Comments
Post has no comments.
Post a Comment




Captcha Image


Subscribe to Receive Complete Website Management Tips & Tricks by Email:

  


Recent Posts


Tags


Archive