Just Before Page Load Event?
12 posts
• Page 1 of 1
Okay, another question about events in Mozilla and Firebird...
What I am looking for is an event that occurs just as a new page has been requested - an 'onBeforeLoad' event if you will. Is there something like this? Basically, I want to be able to work out the URL of the page about to be loaded and then run some code based on the new URL before the page loads. Any help is greatly appreciated... Cheers, Chris <b>Extensions</b>:
[<a href="http://chrispederick.com/work/useragentswitcher/">User Agent Switcher</a> | <a href="http://chrispederick.com/work/webdeveloper/">Web Developer</a>] According to an email :
Perhaps we can help each other ? I have little knowledge of nsI*; although having looked at the .idl files produced by my cvs builds, I think nsIWebProgressListener might be the one to look at ? Unregistering ? : ] Don't hold my feet to the fire on this, but I think the LocationChange event fires before the loading starts, you might give that a try...if not perhaps the StateChange event is what you want...check out nsIWebProgressListener interface reference.
Shelumi`El Jordan S.D.G "[M]en are usually satisfied with bad argument only when their convictions rest on other grounds." --John Oman
If you get it to work, it would be great if you posted your solution here. I'm interested too!
![]() Raph *bump*
cdn: By "unregistering" he means nsIWebProgress :: removeProgressListener(aListener). http://lxr.mozilla.org/mozilla/source/u ... ogress.idl In terms of XUL, browser and tabbrowser have a nsIWebProgress interface. http://www.xulplanet.com/references/ele ... owser.html You can confirm it in this way.
i.e. 1. Create a javascript object "myListener" that implements nsIWebProgressListener. 2. gBrowser.addProgressListener(myListener);( or gBrowser.webProgress.addProgresListener(myListener)) 3. Don't forget to gBrowser.removeProgressListener(myListener) on close the windw. MonkeySage: onLocationChange is after loading the page. So that this event will be fired only once if being redirected 10 times. Sample overlay on Browser/Navigator.
Will this also work in Thunderbird / Mozmail ?
I've just run this code-snippet in URIid code, and I think it fires too early for my purposes : ] In URIid I'm trying to add an ID / classes to the body element of a page, but at the stage that this event handler fires there is no body : ) That code should suit OP fine. Hmm, TB seems a bit more strict than Fx... the difference between browser and tabbrowser.
myListener version 2.0
onload TB
onunload TB
Ah. OK i tried and could intercept addressbar url and change it but load event still loads the page which was entered by user.
Is there not anyway to redirect browser to newly set URL in OnState or onLocationChange event? how cna i navigate new Url? i tried content.location.href in LOAD event of Eventlistener but it doesnt work at all I usually content.document.location.href but this should work to stop a load and load new uri in current tab.
@Torisugari I don't have any experience with progress listeners in Thunderbird, but it may be of interest to you to check out tabbrowser.xml from toolkit.jar from any of the browsers to see that using gBrowser.addProgressListener and gBrowser.webProgress.addProgressListener are somewhat different. gBrowser.webProgress.addProgressListener == function() { [native code] } behaves somewhat differently than gBrowser.addProgressListener which actually calls a method of tabbrowser defined in tabbrowser.xml and adds the new listener to an array with other listeners and then parameters are sequentially passed to each listener in the array when progress occurs while only using only one listener added via gBrowser.webProgress.addProgressListener. I can't remember right off hand what the specific results are in regards to how you go about adding a listener. I believe that one major difference is that when I used gBrowser.addProgressListener the listener I added fired for document and image requests and the corresponding aRequest was passed to my listener methods. However when using gBrowser.webProgress.addProgressListener I was only notified of document requests and aRequest was always null. As I said I am unsure as to the specifics (it has been a while) - I just know that it seemed kind of quirky. You can try it out yourself using console dumps and checking to see if you are getting valid requests as a parameter and what type of requests you are getting.
@dn You would probably accomplish this best by adding your styles/elements when the "DOMContentLoaded" event fires (after the DOM is completely loaded and constructed). You can add/remove your styles like so:
There is a thread here discussing this subject (which I remember posting this in), but unfortunately I was unable to locate it in "My Posts". If you can find it there is some discussion there regarding just what you are trying to do. However it was posted more than 3 months ago (which unfortunately is as far back as you can search).
12 posts
• Page 1 of 1
Return to Extension Development Who is onlineUsers browsing this forum: No registered users and 1 guest |
![]() |