Javascriptでいくつかのコードを記述しましたが、これには変換が必要ですが、これを実現する方法がわかりません。JavaScriptで構文イベントリスナーを変更する
私のコード:
window.addEventListener("load", function() {myExtension.init()}, false);
に
gBrowser.addEventListener("DOMContentLoaded", function(e) {...}), false);
ここで重要なのは、引数eを通過させることです。私は "function(e)"と "myExtension.init(e)"を試しましたが、動作しません。
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);
「トランスフォーム」とまったく同じ意味ですか? – RoToRa
それから、別の何かが間違っています。 'function(e){myExtension.init(e)}'は間違いなく正しいです(イベントオブジェクトを渡したい場合)。この場合、「ウィンドウ」とは何ですか?ブラウザウィンドウまたはページのウィンドウ? –