I'm listening for when a page loads. I get it to display an alert when every page loads. The problem is, is it does not work for the firefox error pages. How could I fix this?
Here is the page with my code:
http://kb.mozillazine.org/On_page_load
I also tried using 'error' instead of 'load'
Extension Help: Using OnLoad event for Firefox error pages
-
- Posts: 39
- Joined: March 14th, 2005, 6:07 pm
-
- Posts: 6108
- Joined: November 18th, 2002, 11:07 am
I don't know if this will help, but here is the file that generates the error page:
http://lxr.mozilla.org/seamonkey/source ... rror.xhtml
which includes netError.js and netError.dtd. It has an onload handler that calls a js method named fillIn().
Because it already has an onload event handler, you can't set one (or at least, you shouldn't). You should probably not do onload, but instaed use addEventListener
http://lxr.mozilla.org/seamonkey/source ... rror.xhtml
which includes netError.js and netError.dtd. It has an onload handler that calls a js method named fillIn().
Because it already has an onload event handler, you can't set one (or at least, you shouldn't). You should probably not do onload, but instaed use addEventListener
-
- Posts: 39
- Joined: March 14th, 2005, 6:07 pm
hmm... interesting. At the bottom of that page it says:
<!--
210 - Note: It is important to run the script this way, instead of using
211 - an onload handler. This is because error pages are loaded as
212 - LOAD_BACKGROUND, which means that onload handlers will not be executed.
213 -->
maybe I could listen for load_background or something...
Also, I am using addEventListener:
<!--
210 - Note: It is important to run the script this way, instead of using
211 - an onload handler. This is because error pages are loaded as
212 - LOAD_BACKGROUND, which means that onload handlers will not be executed.
213 -->
maybe I could listen for load_background or something...
Also, I am using addEventListener:
Code: Select all
window.addEventListener("load", function() { myExtension.init(); }, false);
var myExtension = {
init: function() {
var appcontent = document.getElementById("appcontent"); // browser
if(appcontent)
appcontent.addEventListener("load", this.onPageLoad, true);
var messagepane = document.getElementById("messagepane"); // mail
if(messagepane)
messagepane.addEventListener("load", this.onPageLoad, true);
},
onPageLoad: function(aEvent) {
var doc = aEvent.originalTarget; // doc is document that triggered "onload" event
// do something with the loaded page.
// doc.location is a Location object (see below for a link).
// You can use it to make your code executed on certain pages only.
if(doc.location.href.search("forum") > -1)
alert("a forum page is loaded");
}
}
-
- Posts: 39
- Joined: March 14th, 2005, 6:07 pm
-
- Posts: 39
- Joined: March 14th, 2005, 6:07 pm
Ok, i found this http://kb.mozillazine.org/Progress_listeners . The problem I am having is I can't get it to work. Here is my code:
Overlay.xul:
Overlay.js
I have found that when I put the alerts infront of the gBrowser.addProgressListner the alerts display, but If I do not (as shown), they do not display
Listner.js
Can you find what is wrong? Why doesn't the 'gBrowser.addProgressListener(myListener, Components.interfaces.nsIWebProgress.NOTIFY_STATE_DOCUMENT);' line work?
Overlay.xul:
Code: Select all
<script type="application/x-javascript" src="chrome://program/content/Overlay.js"/>
<script type="application/x-javascript" src="chrome://program/content/Listner.js"/>
<script type="application/x-javascript">
window.addEventListener("load", init, false);
window.addEventListener("unload", uninit, false);
</script>
Overlay.js
Code: Select all
function init()
{
gBrowser.addProgressListener(myListener, Components.interfaces.nsIWebProgress.NOTIFY_STATE_DOCUMENT);
alert("Hello23");
return true;
}
function uninit()
{
gBrowser.removeProgressListener(myListener);
alert("Hello24");
}
I have found that when I put the alerts infront of the gBrowser.addProgressListner the alerts display, but If I do not (as shown), they do not display
Listner.js
Code: Select all
const STATE_START = Components.interfaces.nsIWebProgressListener.STATE_START;
const STATE_STOP = Components.interfaces.nsIWebProgressListener.STATE_STOP;
var myListener = {
stopIsValid: new Boolean(false),
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) {
//aRequest.QueryInterface(Components.interfaces.nsIChannel);
//alert("Wait a moment!\n"+aRequest.URI.spec);
alert("This is the start");
stopIsValid = true;
}
if(aFlag & STATE_STOP) {
if(stopIsValid){
alert("Page Loading Finished");
stopIsValid = false;
}
}
return 0;
},
onLocationChange: function(aProgress, aRequest, aURI) {
alert("locationchanged");
return 0;
},
onProgressChange: function() {return 0;},
onStatusChange: function() {return 0;},
onSecurityChange: function() {return 0;},
onLinkIconAvailable: function() {return 0;}
}
Can you find what is wrong? Why doesn't the 'gBrowser.addProgressListener(myListener, Components.interfaces.nsIWebProgress.NOTIFY_STATE_DOCUMENT);' line work?
Last edited by plasmatic on December 10th, 2005, 11:33 am, edited 1 time in total.