Forum Moderators: open
thanks!
<a href="http://somewhere.com/" title="A link somewhere"
onclick="void(window.open(this.href,'','')); return false;">Link Text</a>
Ps. Target is the second param passed to the window.open() method, you can also just pass null ('') as in the example above to open a new window.
Jordan
Yes, JS can be turned off. That is why I set up the example the way I did:
JS off = follow the link in the same window (acts like regular link).
JS on = open it in the target window w/ the onclick handler.
That way the site is 100% accessible, JS or not.
Ps. 98-99% of users have JS enabled.
Pss. CSS can also be disabled (or forcibly overrided) in a couple of the major browsers (Mozilla / Opera) but that doesn't stop us from designing for the 99% with it enabled.
Jordan
Target="_blank" is also less code than opening the window with JavaScript.
Of course, this is just me talking; I really doubt the W3C will change their standards just because I advised it! :)
Then again, if everyone would only use a tabbed browser instead of IE, and knew how to use it, we could leave new windows/tabs totally up to the user!
In an external .js file i have:
function externalLinks() {
if (!document.getElementsByTagName) return;
var anchors = document.getElementsByTagName("a");
for (var i=0; i<anchors.length; i++) {
var anchor = anchors[i];
if (anchor.getAttribute("href") &&
anchor.getAttribute("rel") == "external")
anchor.target = "_blank";
}
}
window.onload = externalLinks;
and the links that should open in a new window gets the fake attribute "external":
<a href="http://www.foo.com" rel="external">
All links with this fake attribute opens in a new window and it validates.
On a side note i think i heard that the target attribute would be included in the DTD for XHTML again in an upcoming version, but i am not sure.
Kind Regards
Hafnius
Having some so-called webmaster telling me how i should browser is not a sensible option. Moreover any recent graphical browser,except IE, support natively tab-browsing.
Jennifer