HTML and CSS Reference
In-Depth Information
The detachEvent() Method. The detachEvent() method removes an event handler
and its function and is the IE5+ proprietary equivalent of the DOM's removeEventListener() .
FORMAT
object.detachEvent(eventType, function);
EXAMPLE
if (window.detachEvent)
object.detachEvent("onload", init)
There are differences you should be aware of when comparing the W3C model and
the Internet Explorer model:
1. Events always bubble. There is no capturing feature.
2. The this keyword cannot be used to represent the event handling function. The
this keyword refers to the global window object.
See Example 15.23 for examples of Internet Explorer handling.
EXAMPLE 15.23
<html>
<head><title> Internet Explorer Event Handling </title>
<script type="text/javascript">
1
function greetings(){
alert( "Hello World" );
}
// Add an event handler
2
window.attachEvent( "onload", greetings ) ;
// Add another event handler
3
document.attachEvent( "onclick", greetings );
// Add another event handler
document.attachEvent( "onmouseover", greetings);
4
// Remove an event handler just added
5
document.detachEvent( "onmouseover", greetings );
</script>
</head>
<body>
<p>IE has its own way of listening.</p>
</body>
</html>
Search WWH ::




Custom Search