Category:Ajax site tips: Difference between revisions

From GreaseSpot Wiki
Jump to navigationJump to search
No edit summary
Added example script.
Line 11: Line 11:


This is useful since elements you want to attach listeners to might not be in the [[DOM]] yet when the page/script loads.
This is useful since elements you want to attach listeners to might not be in the [[DOM]] yet when the page/script loads.
=== Example scripts ===
* [http://userscripts.org/scripts/show/2419 Gmail attachment reminder]


{{stub}}
{{stub}}


[[Category:Site-specific tips]]
[[Category:Site-specific tips]]

Revision as of 09:04, 13 April 2007

Ajax-driven or JavaScript-heavy sites often require different strategies than when scripting a regular site: elements appear, disappear and change at any time. This page contains some tips for scripting such sites.

Catch bubbling events

This code will tell you what element you click, unless it or some ancestor element does event.stopPropagation():

document.addEventListener('click',function(event) {
  GM_log("Clicked " + event.target);
}, true);

This is useful since elements you want to attach listeners to might not be in the DOM yet when the page/script loads.

Example scripts


This category currently contains no pages or media.