PRB: Event Canceling Behaves Differently in Different Versions of Microsoft Internet Explorer (234472)



The information in this article applies to:

  • Microsoft Internet Explorer (Programming) 4.0
  • Microsoft Internet Explorer (Programming) 4.01
  • Microsoft Internet Explorer (Programming) 4.01 SP1
  • Microsoft Internet Explorer (Programming) 4.01 SP2
  • Microsoft Internet Explorer (Programming) 5

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:
<SCRIPT>
function setStatus() {
    window.status = "Go to this awesome site!";
    return true;
}
</SCRIPT>

<a href="http://www.microsoft.com/" onmouseover="setStatus();">Click Me</a>
				

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:
    <a href="http://www.microsoft.com/" onmouseover="return setStatus();">Click Me</a>
    					
    -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;
    }
    					

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Copy the following HTML code into a file named TestMO.htm:
    <html>
    
    <head>
    <title>Test Event Canceling in IE4/IE5</title>
    <SCRIPT>
    
    function setStatus() {
    	window.status = "Go to this awesome site!";
    	return true;
    }
    
    function unsetStatus() {
    	window.status = "";
    	return true;
    }
    
    </SCRIPT>
    </head>
    
    <body>
    
    <a href="http://www.microsoft.com" onmouseover="setStatus();" onmouseout="unsetStatus();">Microsoft 
    
    Home Page</a><p>
    
    </body>
    
    </html>
    					
  2. Open the page in both Internet Explorer 4 and Internet Explorer 5 and observe the differences.


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.

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:kbFAQ kbprb kbScript KB234472