자바 스크립트에서 일부 변형이 필요한 코드를 작성했지만이를 수행하는 방법을 모르겠습니다.자바 스크립트에서 구문 이벤트 리스너를 변경하십시오.
내 코드 :
gBrowser.addEventListener("DOMContentLoaded", function(e) {...}), false);
여기서 핵심은 인수 전자를 전달하는 것입니다
window.addEventListener("load", function() {myExtension.init()}, false);
에. "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)}'가 틀림 없습니다. 이 경우 '창'은 무엇입니까? 브라우저 창 또는 페이지 창? –