Dev : Extensions : Example Code: Difference between revisions
From MozillaZine Knowledge Base
Jump to navigationJump to search
No edit summary |
(add apply button link) |
||
Line 46: | Line 46: | ||
==Other== | ==Other== | ||
*[[Dev : Extensions : Example Code : Apply button]] | |||
*[[Dev : Extensions : Example Code : Adding items to menus]] | *[[Dev : Extensions : Example Code : Adding items to menus]] | ||
*[[Dev : Extensions : Example Code : File IO]] | *[[Dev : Extensions : Example Code : File IO]] | ||
*[[Dev : Tips : Printing to JSConsole]] | *[[Dev : Tips : Printing to JSConsole]] | ||
*[[Dev : Tips : Inserting text at cursor]] | *[[Dev : Tips : Inserting text at cursor]] |
Revision as of 03:40, 18 September 2004
Preferences
XulPlanet has an article on preferences
Progress Listeners
Progress Listeners alllow extensions to be notified of events assosiated with documents loading in the browser and with tab switching events. Progress Listeners implement the nsIWebProgressListener interface.
- Create an object which implements nsIWebProgressListener:
const STATE_START = Components.interfaces.nsIWebProgressListener.STATE_START; const STATE_STOP = Components.interfaces.nsIWebProgressListener.STATE_STOP; var myListener = { QueryInterface : function(aIID) { if (aIID.equals(Components.interfaces.nsIWebProgressListener) || aIID.equals(Components.interfaces.nsISupportsWeakReference) || aIID.equals(Components.interfaces.nsISupports)) return this; throw Components.results.NS_NOINTERFACE; }, onStateChange:function(aProgress,aRequest,aFlag,aStatus) { if(aFlag & STATE_START) { //This fires when the load event is initiated } if(aFlag & STATE_STOP) { //This fires when the load finishes } return 0; }, onLocationChange:function(aProgress webProgress , aRequest, aURI) { //This fires when the location bar changes i.e load event is confirmed or when the user switches tabs //return 0; }, //For defnitiions of the remaining functions see XulPlanet onProgressChange:function(a,b,c,d,e,f){}, onStatusChange:function(a,b,c,d){}, onSecurityChange:function(a,b,c){}, onLinkIconAvailable:function(a){} }
- Attach the progressListener to a <browser> object, e.g. for firefox:
const NOTIFY_STATE_DOCUMENT = Components.interfaces.nsIWebProgress.NOTIFY_STATE_DOCUMENT; window.getBrowser().addProgressListener(myListener , NOTIFY_STATE_DOCUMENT);
The second argument is a status filter which determines the type of events that will be recieved.