7

What is the best alternative to target="_blank"?

Here is the doctype and html declaration we use:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
BalusC
  • 1,040,783
  • 362
  • 3,548
  • 3,513
tony noriega
  • 7,253
  • 17
  • 50
  • 70

3 Answers3

3

It's just valid as per XHTML Transitional. You can keep using them. It's only invalid as per XHTML Strict.

Regardless, for the case that, you could workaround this with a little help of JavaScript. Replace all target="_blank" by rel="ext" (which is the defacto standard for external links) and run the following (jQuery) script on page load:

$(document).ready(function() {
    $('a[rel=ext]').attr('target', '_blank');
});
Scott Rippey
  • 15,204
  • 5
  • 69
  • 83
BalusC
  • 1,040,783
  • 362
  • 3,548
  • 3,513
  • @RoToRa: For a barking (but not biting) w3 validator when using target attribute on XHTML Strict. – BalusC Dec 09 '10 at 16:31
  • @RoToRa: that's correct. I already found it out and updated the answer at the moment you posted the first comment :) See also the comment on the question. – BalusC Dec 09 '10 at 16:42
0

Similar to the Answer given by BalusC but without the need to modify the html:

http://jsfiddle.net/vC39V/4/

(function () {
    "use strict";
    $(document).ready(function () {
        var LinkTest = {};
        // External Links
        LinkTest.externalLinks = function () {
            $('a[href^=http]').click(function () {
                window.open(this.href);
                return false;
            });
        }();

    });
})(jQuery);
s.Daniel
  • 1,064
  • 12
  • 29
-1

Use JS to make the page open in a new window.

<a href="test.html" onclick="return ! window.open(this.href);">New Window Open</a>
tHeSiD
  • 3,616
  • 3
  • 25
  • 42
  • You will earn headache by selecting this as solution – Vladimir Starkov Aug 28 '12 at 09:23
  • @Kumar why are onclicks considered evil? – Piper May 12 '13 at 05:24
  • 3
    Because there you mix content with function. Say your customer wants all external links to open in a new window, then he/she changes her mind. Inline = go through all documents and edit ; external = comment a line of code. More details: http://stackoverflow.com/questions/6941483/onclick-vs-event-handler – s.Daniel Dec 20 '13 at 10:32