How can I make a function get called after a page has finished loading
I am trying to modify a firefox addon to my personal needs.
Currently my code is this:
var wwatch = Components.classes[NS_WINDOWWATCHER_CONTRACTID].getService(nsIWindowWatcher);
var myWnd = wwatch.openWindow(wwatch.activeWindow, "http://www.google.com", "Test",
开发者_开发百科 "width=600, height=300", null);
myWnd.addEventListener("load", function(e) { alert("inner"); }, false); // doesn't work
// myWnd.onload = function() { alert("inner"); }; // fails totally
I want to show an alert box when the page is finished loading.
With above code the window gets created and the web page gets loaded. But I don't get an alert box. Please tell me, how I can achieve that.
I am new to Javascript and I don't even know how to debug this. The Javascript debugger of Firefox didn't break on any of above lines, although they are obviously executed. The addon which I am adapting to my needs is Torrentserver Handler.
The problem with opening a content window is that the content hasn't started loading, and all your carefully attached event listeners get destroyed when it does.
One approach is to open a chrome browser window and pass it the page that you want it to open. You can then think about adding event handlers as if you were an overlay.
Another approach is to keep with opening the content window, but use one of the various methods to extract the associated chrome window thus giving you somewhere to attach your event handlers.
精彩评论