I’ve written some code in Javascript which needs some transformation but I don’t know how to achieve this.
my code :
gBrowser.addEventListener("DOMContentLoaded", function(e) {...}), false);
into
window.addEventListener("load", function() {myExtension.init()}, false);
The key here is to pass the argument e. I’ve tried “function(e)” and “myExtension.init(e)” but it doesn’t work.
EDIT (all my code – the function code is located at the end of the code):
var myExt_urlBarListener = {
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;
},
onLocationChange: function(aProgress, aRequest, aURI)
{
myExtension.processNewURL(aURI);
},
onStateChange: function(a, b, c, d) {},
onProgressChange: function(a, b, c, d, e, f) {},
onStatusChange: function(a, b, c, d) {},
onSecurityChange: function(a, b, c) {}
};
var myExtension = {
oldURL: null,
init: function(e) {
// Listen for webpage loads
gBrowser.addProgressListener(myExt_urlBarListener,
Components.interfaces.nsIWebProgress.NOTIFY_LOCATION);
},
uninit: function(e) {
gBrowser.removeProgressListener(myExt_urlBarListener);
},
processNewURL: function(aURI) {
if (aURI.spec == this.oldURL)
return;
// now we know the url is new...
this.oldURL = aURI.spec;
var href = aURI.spec;
var vars = [], hash;
var hashes = href.slice(href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
if(vars[0].match(/^http:\/\/www\.google\.fr/))
{
//I want use the event e here
//But it doesn't work
displayBookmarks(e);
}
}
};
//The following doesn't work (I get "e is not defined" in the Error Console)
window.addEventListener("DOMContentLoaded", function(e) {myExtension.init(e)}, false);
window.addEventListener("unload", function() {myExtension.uninit()}, false);
Don’t forget to add the parameter in the function declaration as well: