Microsoft KB Archive/185376

= BUG: Redirection in Anchor Tag Using Location.href Fails =

Article ID: 185376

Article Last Modified on 5/11/2006

-

APPLIES TO


 * Microsoft Internet Explorer 4.0 128-Bit Edition
 * Microsoft Internet Explorer 4.01 Service Pack 2

-



This article was previously published under Q185376



SYMPTOMS
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.



CAUSE
This behavior is by design.



RESOLUTION
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.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce Behavior
  Insert the following HTML into a Web page:   Redirecting within an anchor tag



function GoSomewhere {           location.href = "http://www.microsoft.com";      }         </HEAD>   <BODY>   <A NAME=SomeLink HREF=#book onclick=GoSomewhere>Click Here</A   </BODY>   </HTML>                        </li> <li>Click on the link at the top of the page. The result is that nothing happens.</li></ol>

The following HTML demonstrates two ways to work around this problem using the "javascript:" syntax. Using the workaround demonstrated in Link 2, you can determine the location to which you want to navigate.

Sample Code
<HTML> <HEAD>

Redirecting within an anchor tag</TITLE>

 function GoSomewhere {        location.href = "<WWLINK TYPE="GENERIC"             VALUE="http://www.microsoft.com";">http://www.microsoft.com";</WWLINK>      }   </SCRIPT>

</HEAD> <BODY>

<A NAME=Link1 HREF="javascript:location.href='<WWLINK TYPE="GENERIC"      VALUE="http://www.microsoft.com'">">http://www.microsoft.com'"></WWLINK>      Link 1</A>      <BR>   <A NAME=Link2 HREF="javascript:GoSomewhere">Link 2</A>

</BODY> </HTML>

<div class="references_section">