内容脚本访问网页js [英] content script access to webpage js
问题描述
更新:现在我有这段代码,但它不起作用:
main.js
$ p $ var widgets = require(widget);
var tabs = require(tabs);
var data = require(self)。data;
$ b var widget = widgets.Widget({
id:transfer,
label:Transfer,
content:Transfer,
width:100,
onClick:function(){
tabs.activeTab.attach({
//将使用window.confirm的本地实现
contentScriptFile: data.url(new.js)
});
}
});
new.js:
function foo()
{
call(); //在网页中的功能
}
unsafeWindow.foo();
page-mod
包)并在内容脚本中调用 unsafeWindow.foo()
来调用函数 foo()
从内容脚本。请参阅文档了解更多信息。请确保阅读警告:您正在依靠网页功能按照您期望的方式行事,但可能不会。特别是,如果函数返回了某个内容,并且您想要处理该结果,那么您可能会无意中引入了一个安全漏洞。
I create a firefox addon with the online addon builder. How can one use an existing function on a webpage, from within the addon? This site doesn't belong to me, so I can't bind event listeners, in order to send an event to it from my addon.
Update: Now I have this code but it doesn't work:
main.js
var widgets = require("widget");
var tabs = require("tabs");
var data = require("self").data;
var widget = widgets.Widget({
id: "transfer",
label: "Transfer",
content: "Transfer",
width: 100,
onClick: function() {
tabs.activeTab.attach({
// native implementation of window.confirm will be used
contentScriptFile: data.url("new.js")
});
}
});
new.js:
function foo()
{
call(); // function in webpage
}
unsafeWindow.foo();
You inject a content script into the page (e.g. via page-mod
package) and call unsafeWindow.foo()
in the content script to call function foo()
from the content script. See documentation for more information. Please make sure to read the warnings: you are relying on the web page function to behave the way you expect but it might not. In particular, if the function returns something and you want to process that result, you might inadvertently introduce a security hole.
这篇关于内容脚本访问网页js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!