Hi All,
I am trying to call browser function from extension.
Let's say I have a page, which is opened in Browser window and it contains the following code:
myFunction = function() { //BTW, I tried also window.myFunction ..
alert("I can see you!");
}
I also have the following code in my extension:
window.content.document.defaultView.myFunction(), it works when I am executing from Firebug, but from extension it doesn't have access
to that function.
I can for example access elements in Browser window by the following code: window.content.document.getElementById("...").
I tried to use the follwing, but it in any case I can't call that function.
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator);
var browserWindow = wm.getMostRecentWindow("navigator:browser").content.document;
Can anyone help me with this issue?
Thanks in advance,
David
How to call Browser function from Extension?
-
- Posts: 4
- Joined: April 2nd, 2008, 1:55 pm
- Location: Armenia
-
- Posts: 2810
- Joined: November 15th, 2004, 5:03 am
try this
content.document.location.href = "javascript:(function(){myFunction();})();";
or custom DOM events.
Interaction_between_privileged_and_non-privileged_pages
content.document.location.href = "javascript:(function(){myFunction();})();";
or custom DOM events.
Interaction_between_privileged_and_non-privileged_pages
-
- Posts: 4
- Joined: April 2nd, 2008, 1:55 pm
- Location: Armenia
Thanks max1million,
I actually implemented this using same approach explained in the link you sent me, namely:
On click event, a method is being called in my Browser JS, which takes some values and assigns to my element.value.
Then I do the following:
<code>
var objKeywords = content.document.getElementById("keywordCont");
var clickevent = document.createEvent("MouseEvents");
clickevent.initEvent("click", true, true);
objKeywords.dispatchEvent(clickevent);
</code>
I am dispatching the event and getting the objKeywords.value.
Again, thanks for helping,
David
I actually implemented this using same approach explained in the link you sent me, namely:
On click event, a method is being called in my Browser JS, which takes some values and assigns to my element.value.
Then I do the following:
<code>
var objKeywords = content.document.getElementById("keywordCont");
var clickevent = document.createEvent("MouseEvents");
clickevent.initEvent("click", true, true);
objKeywords.dispatchEvent(clickevent);
</code>
I am dispatching the event and getting the objKeywords.value.
Again, thanks for helping,
David