javascript - Create new function in contentScriptFile in Firefox extension -
i'm developing firefox extension in i've these functions in contentscriptfile of mypanel:
... function myfun(param){ console.log("myfun "+param) } self.port.on('mytrigger',function(value){ $("#myfavdiv").append("<a onclick='myfun(\'"+value+"\')'> click me!</a>") }); ...
i'm including script file (in main.js
):
mypanel = panel.panel({ width: 400, height: 200, contenturl: self.data.url("panel.html"), contentscriptfile: [self.data.url("jquery-1.10.2.min.js") , self.data.url("mscript.js")] });
everything working fine, problem onclick
method dynamically added anchor tag in div#myfavdiv
error thrown when click anchor:
timestamp: 8/10/2013 1:24:48 error: referenceerror: myfun not defined
i tried write myfun
function in main.js
still same error there.
any idea(s)/solution(s)?
i think content script being sandboxed html, when anchor injected html, doesn't know myfun
is. within content script, can bind handler there, keeping within same environment.
self.port.on('mytrigger',function(value){ $("#myfavdiv").append("<a onclick='myfun(\'"+value+"\')'> click me!</a>") $("#myfadiv a").click(myfun); });
Comments
Post a Comment