简体   繁体   中英

call to function in firefox extension main.js from webpage

i want to call a function in a Firefox extension from webpage.let me explain.i have this function in my main.js script.

function extension_function(profname,uurl){

Cu.import('resource://gre/modules/FileUtils.jsm');
var exe = FileUtils.getFile('XREExeF', []); //this gives path to executable
var process = Cc['@mozilla.org/process/util;1'].createInstance(Ci.nsIProcess);
process.init(exe);
var args = ['-P',profname, '-no-remote', uurl];
process.run(false, args, args.length);

}

now i want to call this function from webpage .if i call extension_function("p1","www.fb.com") it give me a error extension_function is undefined ...how can i call my add-on function from webpage.

This page might be of interest to you: click here

In short, you need to dispatch a custom DOM event in your page and listen for it in your extension.

Because you're using the Add-on SDK, take a look here:

https://developer.mozilla.org/en-US/Add-ons/SDK/Guides/Content_Scripts

You basically have to attach a content script to the webpage (you can do it via PageMod or tab.attach), and then you can communicate via postMessage and port object.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM