Re: opening a link in a new window (hope this is ok for this list)

On Monday, February 18, 2002, at 09:15 , Liam Quinn wrote:

> On Tue, 19 Feb 2002, Ian Christie wrote:
[snip]
>> My question is, since the target attribute of the anchor tags is not 
>> valid
>> in XHTML 1.0, how do I make a link that opens in a new window? The
>> attribute is not valid in HTML 4.01 Strict either.
>
> You could use an "onclick" attribute with JavaScript.  Or, much better,
> let the user decide when to open a link in a new window.

I lost the 'let the user decide' argument a while back in one of my 
projects, but also wanted to avoid 'target'. I asked a knowledgeable 
associate for the best javascript approach; i.e., one that preserves the 
integrity of the link w/o javascript, minimizes script clutter in html, 
etc. He cooked up this, a close variant of which I've now got in a 
linked script for site-wide availability: 
<http://glish.com/misc/fahrner.html>.

I consider it a feature that no new window is spawned if javascript is 
off. I suppose that "empowered" Web users, who are inclined to turn js 
off, are more likely than not to resent new windows being opened on 
them. Just be sure not to put any silly "close this window" links in the 
spawned window(s), especially if you are trying to maintain 
state/session control.

There's one bit of 'target' functionality that this script fails to 
capture: the spawned window can get lost behind others. After the 
initial load, subsequent ones fail to focus the target. Neither my 
associate nor i could come up with an elegant, cross-browser means of 
achieving this. We resort, inelegantly, to sticking 
onload="self.focus()" in the body of all of the targeted documents. If 
you want to link to docs that you don't control, you are out of luck.

I'm with Liam though: it's almost always best to let users decide how to 
manage resources under their control: printers, windows, etc.

Received on Tuesday, 19 February 2002 12:14:57 UTC