Microsoft KB Archive/234472

= PRB: Event Canceling Behaves Differently in Different Versions of Microsoft Internet Explorer =

Article ID: 234472

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
 * Microsoft Internet Explorer 4.01 Service Pack 1
 * Microsoft Internet Explorer 4.01 Service Pack 2
 * Microsoft Internet Explorer 5.0

-



This article was previously published under Q234472



SYMPTOMS
In scripting, you can signal to the browser that you have handled an event by returning true from within the event handler function. If you are mousing over a link, for example, and want to replace the text that appears in the window's status bar, you would return true from your onmouseover handler in order to prevent Microsoft Internet Explorer from overwriting your custom status text with the URL link:  function setStatus { window.status = "Go to this awesome site!"; return true; } 

Click Me

While such canceling of events might appear to work fine in Microsoft Internet Explorer 4, it sometimes breaks in Internet Explorer 5, even though the event handler function is returning true. For the example in this section in Internet Explorer 5, you will see the HREF text appear in the status window instead of your custom message.



CAUSE
Event canceling was changed slightly in Internet Explorer 5 for compatibility with Netscape Navigator.



RESOLUTION
To make your Internet Explorer 4 code work in Internet Explorer 5, do one of the following:   Put the "return" keyword next to your function handler: Click Me -or-

  Instead of returning true from the handler, set the returnValue property of the event Object to true: function setStatus { window.status = "Go to this awesome site!"; window.event.returnValue = true; }                   

<div class="status_section">

STATUS
This behavior is by design.

<div class="moreinformation_section">

Steps to Reproduce Behavior
<ol>  Copy the following HTML code into a file named TestMO.htm:

Test Event Canceling in IE4/IE5 

function setStatus { window.status = "Go to this awesome site!"; return true; }

function unsetStatus { window.status = ""; return true; }

</SCRIPT>

<a href="http://www.microsoft.com" onmouseover="setStatus;" onmouseout="unsetStatus;">Microsoft

Home Page</a>

</li> Open the page in both Internet Explorer 4 and Internet Explorer 5 and observe the differences.</li></ol>

The third-party products that are discussed in this article are manufactured by companies that are independent of Microsoft. Microsoft makes no warranty, implied or otherwise, regarding the performance or reliability of these products.

<div class="references_section">