BUG: Redirection in Anchor Tag Using Location.href Fails (185376)



The information in this article applies to:

  • Microsoft Internet Explorer (Programming) 4.0
  • Microsoft Internet Explorer (Programming) 4.01

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.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Insert the following HTML into a Web page:
       <HTML>
       <HEAD>
          <TITLE>Redirecting within an anchor tag</TITLE>
    
          <SCRIPT>
    
             function GoSomewhere()
             {
                location.href = "<WWLINK TYPE="GENERIC"    VALUE="http://www.microsoft.com";">http://www.microsoft.com";</WWLINK>
          }
          </SCRIPT>
       </HEAD>
       <BODY>
       <A NAME=SomeLink HREF=#book onclick=GoSomewhere()>Click Here</A
       </BODY>
       </HTML>
    						
  2. Click on the link at the top of the page. The result is that nothing happens.
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>

   <TITLE>Redirecting within an anchor tag</TITLE>

   <SCRIPT>
      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>
				

REFERENCES

For more information about developing Web-based solutions for Microsoft Internet Explorer, visit the following Microsoft Web sites:

Modification Type:MajorLast Reviewed:5/11/2006
Keywords:kbbug kbpending KB185376