PRB: HREF="#" with Event Code Behaves DifferentlyID: Q190244
|
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='http://www.microsoft.com';">
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.
window.event.returnValue = false;
This causes the onclick event to fire and not try to navigate to the
HREF specified by the link.
style="cursor:hand; text-decoration:underline; color:blue; font-family:times new roman"
This behavior is by design.
<HTML>
<HEAD>
<TITLE> title </TITLE>
</HEAD>
<BODY>
<A HREF="#" onclick="window.location.href='http://www.microsoft.com';">
problem repro </A>
<br>
<A HREF="#" onclick="window.location.href='http://www.microsoft.com';
window.event.returnValue=false;">
solution 1: add window.event.returnValue=false statement</A>
<br>
<A HREF="JavaScript:window.location.href='http://www.microsoft.com';">
solution 2: replace HREF value with JavaScript:[code] </A>
<br>
<A onclick="window.location.href='http://www.microsoft.com';"
onmouseover="window.status='http://www.microsoft.com';"
onmouseout="window.status='';"
style="cursor:hand; text-decoration:underline; color:blue;
font-family:times new roman">
solution 3: remove HREF attribute and use CSS </A>
</BODY>
</HTML>
For more information, please see the MSDN Web Workshop:
http://msdn.microsoft.com/workshop/default.asp
http://msdn.microsoft.com/scripting/
Additional query words:
Keywords : kbhtml kbIE400 kbIE401bug kbScript kbIE500
Version : WINDOWS:4.0,4.01
Platform : WINDOWS
Issue type : kbprb
Last Reviewed: April 30, 1999