window.open(this.href) vs target=”_blank”

Posted in: FeedLounge, Development

Like most people who have migrated to XHTML for web development, I stopped using target="_blank" for opening links in new windows in favor of onclick="window.open(this.href); return false". They accomplish the same thing (opening the link in a new window) and the second one validates.

However, as I was implementing the often requested “open external links in new windows” preference for FeedLounge, I ended up falling back on the target="_blank" method for one simple reason: it works better.

Actually, I guess it isn’t so much that it works better as it is that browsers handle it better and more consistently.

The JavaScript window.open method wants to pop a window no matter what. Even if you do a modified click to open the link in a new tab, you’ve got a 50-50 chance of getting the same link being opened in a new window as well1. When using the target method, browsers seem to have all decided that a new tab is just as good as a new window, and that there is no need to pop that superfluous window.

From a coding perspective, I can understand the browser’s behavior with the window.open method. It received 2 commands:

  1. Open this link in a new tab.
  2. Open this link in a new window.

and it happily did both. Unfortunately, this isn’t the behavior that users actually want. Until we’ve got a standards compliant way of coding up the behavior that users want (open in a new tab if they hold down the modifier key), I’m going with the solution that will make my users happy - ugly non-compliant hack or not.

  1. A major annoyance of mine on Yahoo! sports pages. [back]

Popularity: 12% [?]

Posted December 30th, 2005 @ 10:39 AM

3 Replies

  1. shorty114 adds this Comment:

    You could use transitional XHTML, I think that has the taget attribute… I cant’ remember exactly though. That way target=”_blank” would be valid.

    December 30th, 2005 at 12:59 pm

  2. Alex adds this Comment:

    The specs are available for your reading pleasure.

    December 30th, 2005 at 1:24 pm

  3. Joe Everett adds this Comment:

    Do you have any idea how ANNOYING it is to want to view a web page and see a google ad sitting RIGHT ON TOP OF THE TEXT…and NO exit button?
    Yeah…pretty dang annoying. Why on earth would you allow Google to do that to your web page. An ad with a exit button…sure…pain in the behind but at least I can exit it and move on…but THIS?

    Jesus H. what are you thinking?

    November 17th, 2008 at 8:14 am

Add a Comment

Please note: Use of a non-personal web site or blog in the field below and/or comments that are off-topic, personal attacks, or support requests will likely be removed at my discretion.

Note: This post is over 3 years old. You may want to check later in this blog to see if there is new information relevant to your comment.

WordPress 2.0 Tooltips are Wrong for Mac Users » « Tasks Pro™ 1.6rc2 and Tasks 2.6rc2

About This Site

This is the personal web site of Alex King, a web developer in Denver, Colorado USA. More...


Crowd Favorite

Crowd Favorite is my software and web development business.

We build web applications, design and develop custom WordPress themes and plugins, and build custom sites using WordPress as a CMS.


I also have a tumblog that aggregates my online content from other services (Twitter, Flickr, del.icio.us. etc.).

America

Ads

Get Group Health Insurance
Car Loans available here