OZONE Asylum
Forums
DHTML/Javascript
Cross browser addEventListener function
This page's ID:
31837
Search
QuickChanges
Forums
FAQ
Archives
Register
Edit Post
Who can edit a post?
The poster and administrators may edit a post. The poster can only edit it for a short while after the initial post.
Your User Name:
Your Password:
Login Options:
Remember Me On This Computer
Your Text:
Insert Slimies »
Insert UBB Code »
Close
Last Tag
|
All Tags
UBB Help
Instead of testing for window.event, you are better off testing for the presence of the calls you wish to use: [code]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>Simple Event Example</title> <script type="text/javascript"> function addEventHandler(oNode, evt, oFunc, bCaptures) { if (document.addEventListener) { // Safari, Chrome, Fx, etc oNode.addEventListener(evt, oFunc, bCaptures); } else if (document.attachEvent) { // IE oNode.attachEvent('on' + evt, oFunc); } else { // If all else fails oNode['on' + evt] = oFunc; } } function onLinkClicked(e) { alert("You clicked the link!"); } function setUpClickEvent(e) { addEventHandler(document.getElementById('clickLink'), 'click', onLinkClicked, false); } addEventHandler(window, 'load', setUpClickEvent, false); </script> </head> <body> <a href="#" title="click me" id="clickLink">Click Me!</a> </body> </html>[/code] Dan \
Loading...
Options:
Enable Slimies
Enable Linkwords
« Backwards
—
Onwards »