HTML Code

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

In Uncategorized by churchbuzz

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>