Entry
How do I script the target of a link?
Apr 5th, 2000 05:05
Martin Honnen,
Link elements have a
target
property (at least in NN4+ and IE4+). This property is readable and
writable. Note that with NN4 when you read
document.links[linkIndex].target
of a link element which has no TARGET attribute that it returns
null
and not the empty string.
Here are two example uses:
<A HREF="http://JavaScript.FAQTs.com"
TARGET="aTarget"
ONCLICK="open(this.href,
this.target,
'menubar=0,location=0,statusbar=0,scrollbars=1,resizable=1,');
return false;"
>JavaScript.FAQTs.com</A>
This uses the href and the target property of the link to open a window
with specific features instead of the standard window. In case
JavaScript is disabled or not supported the link nevertheless works.
<A HREF="http:://JavaScript.FAQTs.com"
ONCLICK="this.target = 'win' + new Date().getTime();
return true;"
>
JavaScript.FAQTs.com
</A>
This sets the link target to a new target name every time the link is
clicked.