Running Javascript Code Entered on a Page When Developing a Firefox Extension

I am developing a Firefox extension that places a button on the status bar. When the button is clicked, the extension adds some Javascript to the current page. This Javascript has a function that I would like to use with some parameters. I was able to enter the code, I checked the page through Firebug and verified that JS was entered. How can I call a Javascript function on a page from my extension?

- Additional Information

Here is the code I use to enter my Javascript:

var doc = window.content.document;

//Add the script
var visibilityJS = doc.createElement("script");
visibilityJS.setAttribute("type", "text/javascript");
visibilityJS.setAttribute("charset", "UTF-8");
visibilityJS.setAttribute("src", "chrome://visibility/content/scripts/visibility.js");
head.appendChild(visibilityJS);

//Call the function
alert("Executing testfunction");
window.content.document.defaultView.testFunction();

.. and the code inside my JS file, which I will enter. i.e. visibility.js

window.testFunction = function() {
    alert("Message");
}

Thank.

+3
source share
2

. . Felix .

window.content.document.defaultView.wrappedJSObject.testFunction();
+4

( window), , gBrowser object:

gBrowser.contentDocument.defaultView.yourObject
          ^-- HTML document  ^
              object         |-- window object

, window document . Firefox -.

+2

Source: https://habr.com/ru/post/1775642/


All Articles