PRB: HREF="#" with Event Code Behaves Differently

Exención de responsabilidades de contenido KB retirado

Este artículo se refiere a productos para los que Microsoft ya no ofrece soporte técnico. Por tanto, el presente artículo se ofrece "tal cual" y no será actualizado.


The following HTML statement, when clicked, will navigate to a new URL in Internet Explorer 3.0, but fails to do so in Internet Explorer 4.0:

<A HREF="#" onclick="window.location.href='';"> 
problem repro </A>


Internet Explorer 4.0 waits until all events from the <A> tag are finished before processing the HREF attribute, so window.location.href will be overwritten by HREF="#".


Here are three ways to make this tag work as expected in Internet Explorer 4.0. See the "More Information" section for a complete code listing.

  • Add this statement to the code:

    window.event.returnValue = false;
    This causes the onclick event to fire and not try to navigate to the HREF specified by the link.
  • Replace the HREF value with JavaScript:[code].
  • Eliminate HREF="#" and make it look like an anchor with Cascading Style Sheets (CSS) by adding this style attribute to the anchor:

    style="cursor:hand; text-decoration:underline; color:blue; font-family:times new roman"


This behavior is by design.

More Information

Steps to Reproduce Behavior

The following HTML code demonstrates the problem and the resolutions.

<TITLE> title </TITLE>

<A HREF="#" onclick="window.location.href='';">
problem repro </A>
<A HREF="#" onclick="window.location.href='';
solution 1: add window.event.returnValue=false statement</A>
<A HREF="JavaScript:window.location.href='';">
solution 2: replace HREF value with JavaScript:[code] </A>
<A onclick="window.location.href='';"
style="cursor:hand; text-decoration:underline; color:blue;
font-family:times new roman">
solution 3: remove HREF attribute and use CSS </A>


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


Id. de artículo: 190244 - Última revisión: 06/22/2014 - Revisión: 1