BUG: Redirection in Anchor Tag Using Location.href FailsID: Q185376
|
Placing a call to location.href in an anchor tag does not cause navigation to be redirected to that HREF when the user clicks on the link.
This behavior is by design.
The workaround is to use the "javascript:" syntax for the HREF attribute of the anchor tag. Please see the MORE INFORMATION section for sample code that demonstrates this workaround.
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.
<HTML>
<HEAD>
<TITLE>Redirecting within an anchor tag</TITLE>
<SCRIPT>
function GoSomewhere()
{
location.href = "<LINK TYPE="GENERIC" VALUE="http://www.microsoft.com";">http://www.microsoft.com";</LINK>
}
</SCRIPT>
</HEAD>
<BODY>
<A NAME=SomeLink HREF=#book onclick=GoSomewhere()>Click Here</A
</BODY>
</HTML>
<HTML>
<HEAD>
<TITLE>Redirecting within an anchor tag</TITLE>
<SCRIPT>
function GoSomewhere()
{
location.href = "<LINK TYPE="GENERIC" VALUE="http://www.microsoft.com";">http://www.microsoft.com";</LINK>
}
</SCRIPT>
</HEAD>
<BODY>
<A NAME=Link1
HREF="javascript:location.href='<LINK TYPE="GENERIC" VALUE="http://www.microsoft.com'">">http://www.microsoft.com'"></LINK>
Link 1</A>
<BR>
<A NAME=Link2 HREF="javascript:GoSomewhere()">Link 2</A>
</BODY>
</HTML>
For more information, please see the MSDN Web Workshop:
http://msdn.microsoft.com/workshop/default.asp
Additional query words: kbHTMLObj kbScript
Keywords : kbIE400 kbIE401 kbDSupport
Version : WINDOWS:4.0,4.01
Platform : WINDOWS
Issue type : kbbug
Last Reviewed: July 22, 1999