I'm going to develop a Firefox extension which should put a button in the loaded pages, when the tag: <input type="file" ... >
is found and a file has been selected.
我将开发一个Firefox扩展,当找到标签:并选择了一个文件时,它应该在加载的页面中放置一个按钮。
Likewise, I think the skype toolbar does a similar thing: when a website contains a phone number, the Skype extension automatically converts it into a button that can be clicked to call skype contacts.
同样,我认为skype工具栏做了类似的事情:当一个网站包含一个电话号码时,Skype扩展会自动将其转换为一个按钮,可以点击该按钮来呼叫Skype联系人。
I'm on a GNU/Linux system, and unfortunately the skype extension does not work on Linux versions of Firefox/skype, so I can't even try to reverse engineer anything...
我正在使用GNU / Linux系统,不幸的是,skype扩展在Firefox / skype的Linux版本上不起作用,所以我甚至无法对任何东西进行逆向工程......
The firefox extension contains the file overlay.js: this file contains the main logic for the extension. Here I can find <input type="file" ... >
nodes simply with this code:
firefox扩展包含文件overlay.js:此文件包含扩展的主要逻辑。在这里,我只需使用以下代码即可找到节点:
onFileChosen: function(aEvent) {
var input = aEvent.explicitOriginalTarget;
if(input.type=="file"){
alert(input.value); }
}
window.addEventListener("change", function(e) {xpitest.onFileChosen(e)},false);
So, when a file has been chosen, an alert window appears and shows the file name.
因此,当选择文件时,会出现一个警告窗口并显示文件名。
But, how can I put a button in the page when a file has been chosen?
但是,当选择文件时,如何在页面中放置一个按钮?
I've been trying with the various document.parentNode and similars, but nothing seems to work.
我一直在尝试使用各种document.parentNode和similars,但似乎没有任何工作。
Or is it possible that I can't put stuff into the loaded page?
或者我有可能无法将内容放入加载的页面中?
Thanks
1 个解决方案
#1
From the chrome context, you can get the current content document (e.g. the page with the file chooser) using top.window.content.document . At that point, it's just like your JS is running on the page. If that doesn't help, please post your code with as much info as possible. See also Working with windows in chrome code.
在chrome上下文中,您可以使用top.window.content.document获取当前内容文档(例如带有文件选择器的页面)。那时,就像你的JS在页面上运行一样。如果这没有帮助,请使用尽可能多的信息发布您的代码。另请参阅在chrome代码中使用Windows。
And you definitely can inject things into the page.
你肯定可以在页面中注入东西。
#1
From the chrome context, you can get the current content document (e.g. the page with the file chooser) using top.window.content.document . At that point, it's just like your JS is running on the page. If that doesn't help, please post your code with as much info as possible. See also Working with windows in chrome code.
在chrome上下文中,您可以使用top.window.content.document获取当前内容文档(例如带有文件选择器的页面)。那时,就像你的JS在页面上运行一样。如果这没有帮助,请使用尽可能多的信息发布您的代码。另请参阅在chrome代码中使用Windows。
And you definitely can inject things into the page.
你肯定可以在页面中注入东西。