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:
- Open this link in a new tab.
- 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.
- A major annoyance of mine on Yahoo! sports pages. [back]
This post is part of the project: FeedLounge. View the project timeline for more context on this post.
You could use transitional XHTML, I think that has the taget attribute… I cant’ remember exactly though. That way target=”_blank” would be valid.
The specs are available for your reading pleasure.
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?
@Joe Everett
Seems its only you that has that issue, no ads here. Maybe watch your browsing habits and you wont get those types of things in your PC 😉