>All Tutorials 
Ajax and .NET Ajax and .NET RSS XML
Ajax and ColdFusion Ajax and ColdFusion RSS XML
Ajax and Java Ajax and Java RSS XML
Ajax and PHP Ajax and PHP RSS XML
Ajax and SOA Ajax and SOA RSS XML
Ajax Goodies Ajax Goodies RSS XML
Ajax Tool Ajax Tool RSS XML
Facebook MockAjax Facebook MockAjax RSS XML
Google Web Toolkit Google Web Toolkit RSS XML
JavaScript Framework JavaScript Framework RSS XML
Ruby on Rails Ruby on Rails RSS XML
Technique Introduction Technique Introduction RSS XML
Without XMLHttpRequest Without XMLHttpRequest RSS XML
Yahoo! UI Yahoo! UI RSS XML

Cross-Browser Event Handling and Memory Leaks - event function var eventname listenerfn registration listener instance

 
Registered tutorials: 501
Registered Users: 33126



Rating: 0 out of 0 votes cast


  
Category: Technique Introduction

Cross-Browser Event Handling and Memory Leaks

Digg this   Post to del.icio.us

Abstract: In this article, the author discusses how organize the cross-browser event handling and avoid most common problems with memory leaking

In the "old-style" event registration model, you would typically register events by assigning functions to the onevent property of DOM elements:

elem.onclick = function() {     alert("You clicked me"); }

The problem with that approach is that you can only assign a single event handler function to any given event. All modern browsers support more advanced event registration mechanisms so you can attach multiple event listeners to any given event, though, as usual, those mechanisms vary across platforms. This recipe can be used to register and unregister event listeners in all modern browsers:

function addEventListener(instance, eventName, listener) {     var listenerFn = listener;     if (instance.addEventListener) {         instance.addEventListener(eventName, listenerFn, false);     } else if (instance.attachEvent) {         listenerFn = function() {             listener(window.event);         }         instance.attachEvent("on" + eventName, listenerFn);     } else {         throw new Error("Event registration not supported");     }     return {         instance: instance,         name: eventName,         listener: listenerFn     }; }  function removeEventListener(event) {     var instance = event.instance;     if (instance.removeEventListener) {         instance.removeEventListener(event.name, event.listener, false);     } else if (instance.detachEvent) {         instance.detachEvent("on" + event.name, event.listener);     } }

Read Full Tutorial...



Reviews:

Rate and Review This Site

No reviews yet


Statistic Information About this Resource:


Total Hits: 20
Unique Hits: 14


  Daily Weekly Monthly
  Unique Total Unique Total Unique Total
Average 0.1 0.1 0.4 0.4 0.7 0.8
Current 0 0 0 0 0 0
Previous 0 0 1 1 4 4
Nov 29 0 0 2 2 0 0
Nov 28 0 0 0 0 0 0
Nov 27 0 0 1 1 0 0
Nov 26 0 0 0 0 1 1
Nov 25 1 1 0 0 1 2
Nov 24 0 0 0 0 0 0
Nov 23 0 0 0 0 1 1
Nov 22 0 0 0 0 0 0
Highest 1 4 2 4 4 5


Script Execution Time: 16.88522 | SQL Queries: 10 | Members: 501
Ajax Tutorial Top List - Powered by Aardvark Topsites PHP 5.1.2