I know that most links should be left up to the end-user to decide how to open, but we can’t deny that there are times you almost ‘have to’ force into a new window (for example to maintain data in a form on the current page).
What I’d like to know is what the consensus is on the ‘best’ way to open a link in a new browser window.
I know that <a href='url' target='_blank'> is out. I also know that <a href='#' onclick='window.open(url);'> isn’t ideal for a variety of reasons. I’ve also tried to completely replace anchors with something like <span onclick='window.open(url);'> and then style the SPAN to look like a link.
One solution I’m leaning towards is <a href='url' rel='external'> and using JavaScript to set all targets to ‘_blank’ on those anchors marked ‘external’.
Are there any other ideas? What’s better? I’m looking for the most XHTML-compliant and easiest way to do this.
UPDATE: I say target=’_blank’ is a no no, because I’ve read in several places that the target attribute is going to be phased out of XHTML.
I am using the last method you proposed. I add rel=’external’ or something similar and then use jQuery to iterate through all links and assign them a click handler:
I find this the best method because:
hrefattribute)