Firefox Add-ons: How do I call a function from inside an injected HTML button
-
I have a code module in my Firefox extension that I am trying to call from an input button I inject onto the HTML page. The problem is it doesn't allow me to call the function from my event listener. Tried many different approaches but I thought this was best one and did not work. My code: onPageLoad: function(aEvent) { Components.utils.import("chrome://my_ext/content/writeFile.jsm", my_ext); //alert(foo()); - foo() is an function in the above code module I import var doc = aEvent.originalTarget; // doc is document that triggered "onload" event var mEvent = doc.createEvent("Events"); mEvent.initEvent("mClick", true, true); var fblike = doc.getElementById("LikePluginPagelet"); var button = doc.createElement("input"); button.setAttribute("type", "button"); button.setAttribute("value", "My Button"); button.addEventListener("click", function() { button.dispatchEvent(mEvent); }, false); fblike.appendChild(button, fblike); doc.addEventListener("mClick", function() {alert(foo()); }, false); }, My writeFile.jsm: var EXPORTED_SYMBOLS = ["foo"]; function foo() { return "foo test"; }
-
Answer:
// Note second argument is not necessary.// Default value is correct.Components.utils.import("chrome://my_ext/content/writeFile.jsm");// You might want to just call foo() here as a test, to// make sure it gets imported correctly.var elm = document.createElement("button");elm.addEventListener("click", foo);doc.body.appendChild(elm);
Aaron Boodman at Quora Visit the source
Related Q & A:
- How to call a function with parameter in a bash script?Best solution by tldp.org
- how to call a function in Python in another function?Best solution by Yahoo! Answers
- How can I use a button to retrieve a phone 'number' from contacts?Best solution by Stack Overflow
- How to call a function asynchronously in PHP?Best solution by Stack Overflow
- How do I call a cell phone in Australia?Best solution by wiki.answers.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.