Monday, August 08, 2011

Safari URL opens new window

Here's a strange quirk I encountered while working with Safari mobile: HTML anchors (<a href="http://www.blogger.com/something.html">click</a>) open a new Safari browser instance---every time.

Now that can't be right. As it turns out, this is indeed the standard behavior when the target attribute is not explicitly set in the anchor. Apple does provide a work around setting:

http://www.naquah.net/blog/dennis/2008/03/21/how-to-enable-single-window-mode-in-safari

There are many instances when web designers don't need targets, and they are omitted. For most browsers, when the target is not explicitly set, the browser default behavior is _self. See the table from w3cschool:

http://www.w3schools.com/tags/att_a_target.asp

Attribute Values
ValueDescription
_blankOpen the linked document in a new window or tab
_selfOpen the linked document in the same frame as it was clicked (this is default)
_parentOpen the linked document in the parent frameset
_topOpen the linked document in the full body of the window
framenameOpen the linked document in a named frame


The kicker is that Safari uses _blank as the default instead of self. The solution for web designers? Explicitly set the target attribute to _self for every anchor. A bit of a hassle, but the best way to ensure that a new window does not open up with each hyperlink click.


No comments: