background preloader

Events

Facebook Twitter

On page load - MDC. This article is for XUL/JavaScript developers who want to have custom code executed each time a new page is loaded in browser/mail.

On page load - MDC

If you need finer control over custom code execution—for example, as documents are loading or when tabs are switched—see Progress Listeners. Progress listeners allow extensions to be notified of events associated with documents loading in the browser and with tab switching events. Progress listeners implement the nsIWebProgressListener interface. Creating an overlay First, you need to create an overlay to one (or more, depending on which applications you target) of the following XUL documents: Attaching a script Attach a script to your overlay (see "Attaching a Script to an Overlay") that adds a load event listener to appcontent element (browsers) or messagepane (mail): Current Firefox trunk nightlies will fire the onPageLoad function for not only documents, but xul:images (favicons in tabbrowser).

For appcontent and similarly for messagepane. Mobile/Fennec/CodeSnippets. Here you should find a set of useful code snippets to help you work with Fennec.

Mobile/Fennec/CodeSnippets

Although Fennec is built on XUL and JS, like Firefox, the architecture between Firefox and Fennec is different. Each snippet normally includes some code to run at initialization. These are best run using a load listener. These snippets assume they are run in the context of a browser window. Detecting page loads in a Firefox Extension. Posted: September 15th, 2008 | Author: Tim | Filed under: coding, firefox extensions | Tags: addeventlistener, detecting, event, Firefox Extension, gbrowser, page loads | 4 Comments » Detecting page loads is a useful ability.

It’s easy enough to throw in a gBrowser.addEventListener(“load”, function_name, true); DOMContentLoaded. Progress Listeners - MDC. Progress Listeners Progress listeners allow extensions to be notified of events associated with documents loading in the browser and with tab switching events.

Progress Listeners - MDC

Progress listeners implement the nsIWebProgressListener interface. Note that if you just want to execute your code each time a page loads, you can use an an easier method, onPageLoad(). Note that onPageLoad does not fire for back button clicks. In the examples below the progress listener is attached to the tabbrowser, which means you don't get any notifications for inactive tabs.

Example. AddProgressListener for ALL Tabs?! This is frustrating me.

addProgressListener for ALL Tabs?!

How come the progress listener does not get called for a page loading in a tab that does not have focus?! I can't figure out why the Mozilla interface doesn't support this. The "close" event handler is not working, any help. I got my close event worked..

The "close" event handler is not working, any help

All I worked was, removed the "alert()"s and it worked a couple of times. But again started not to work.. I then removed try{} and catch{} blocks (catch again had an "alert()") and it works every time now. I am just a beginner, developing this extension as just one module of my application; I have to install, uninstall everytime I make a change.. I think one having good knowledge on JavaScript and extension writing should Research and place the right thing over here so otheres can do it easily.

What I think is that one can not use dialog boxes while the window is closing.. since the alert dialog box comes as MODAL dialog box and it needs a parent window and while the FF window is closing, it does not allow any dialog box to display or the dialog box gets failed to achieve the parent window OR maybe something else. How to get tab id from "DOMContentLoaded" event, Firefox - Unix. JavaScript Kit- Event Object. Event Object Last updated: March 15th, 2009 The Event object keeps tracks of various events that occur on the page, such as the user moving the mouse or clicking on the link, and allows you to react to them inside your scripts.

JavaScript Kit- Event Object

Related Tutorials. [Project_owners] Getting Source Tab When Listening to http-on-mo. Gecko-Specific DOM Events - MDC. Events - MDC. « XUL Reference home The following tables describe the event handler that are valid for most XUL elements.

Events - MDC

The events listeners can be attached using addEventListener and removed using removeEventListener. Some of the events can be attached using attributes as well. When attaching event listeners using attributes, be aware that only one listener can be attached at a time. AddProgressListener for ALL Tabs?! Getting a Progress Listener to work. Following from the Event listeners & logging browsing session this topic is about the NSIWebProgressListener object.

Getting a Progress Listener to work

And then tried to incorporate a progress listener to my overlay. The resulting code is below and it didn't work. My questions are at the bottom of this post and perhaps they are not so much specific to my extension, so before troubling reading the following code just skip to the end of the post. Code: Select all const STATE_START = Components.interfaces.nsIWebProgressListener.STATE_START;const STATE_STOP = Components.interfaces.nsIWebProgressListener.STATE_STOP;window.addEventListener("load", function(e) {myext.onLoad(e);}, false); var myListener ={/*see below*/} Nowthe myListener object consists of the following. onLocationChange: function(aProgress, aRequest, aURI){ // This fires when the location bar changes; i.e load event is confirmed // or when the user switches tabs.

How to add ProgressListener to each Tab. Hi, guys, I am just starting to learn FF ext, I am trying to add ProgressListener to each Tab when Tab is created, then record some browsing history for each tab, for example, last visited url, load counts, etc, so if I have 5 opened tabs, I should have 5 records for last visited url, load counts, etc.

How to add ProgressListener to each Tab

What I am doing right now is: 1. add load and unload event listeners for window, when window load, I add tabcontainer listener to catch actions to tab. Code: Select all function InitialWindow() { var container = gBrowser.tabContainer; container.addEventListener("TabOpen", OnTabOpen, false); container.addEventListener("TabMove", OnTabMove, false); container.addEventListener("TabClose", OnTabClose, false);} function UnloadWindow() { var container = gBrowser.tabContainer; container.removeEventListener("TabOpen", OnTabOpen, false); container.removeEventListener("TabMove", OnTabMove, false); container.removeEventListener("TabClose", OnTabClose, false);}

Event listeners & logging browsing session. Hello, I am developing an extension that should log user browsing behavior. Things that I am interested in are parameters like: url's browsedlink clickthroughtime spent on pageisbookmarkedetc.