[英]Trigger Javascript function in Firefox (or any other browser) from an external program
I would like to trigger a Javascript function on an already existing website I don't own by pressing a key. 我想通过按键来在我不拥有的现有网站上触发Javascript函数。
Example : trigger my_function('my parameter 1'); 示例:触发my_function('my参数1'); when I press the 1 key on the keyboard. 当我按键盘上的1键时。
I can type manually the command on the Firefox's debugger console, it works. 我可以在Firefox的调试器控制台上手动键入命令,它可以正常工作。 But I can't figure a simple way to trigger the Javascript function from an external program. 但是我找不到从外部程序触发Javascript函数的简单方法。 Can I use Firefox command line ? 我可以使用Firefox命令行吗? EventGhost ? EventGhost? AutoHotKey ? AutoHotKey? Should I write a Firefox extension ? 我应该编写Firefox扩展程序吗?
If your solution implies the use of another web browser you're welcome ! 如果您的解决方案意味着要使用其他Web浏览器,欢迎您!
I suggest you to look at this https://api.jquery.com/keydown/ . 我建议您看一下https://api.jquery.com/keydown/ 。 Jquery could be the solution but the problem isn't clear. jQuery可能是解决方案,但问题尚不清楚。 The site you're talking about is yours or you want to inject this trigger event from outside? 您正在谈论的站点是您的站点,还是您想从外部注入此触发事件? Do you want this trigger to be injected every time? 您是否希望每次都触发该触发器?
If it's just a one-night stand you can use the browser console but if it's not you could be interested in developing an add-on or a greasemonkey extention. 如果只是一个晚上的看台,则可以使用浏览器控制台,但是如果不是,则可能会对开发附加组件或油脂猴子扩展感兴趣。
Update: Yo can use eventghost, specifically the window plugin http://www.eventghost.org/docs/pluginlist.html , to trigger a keypress on firefox. 更新:您可以使用eventghost(特别是窗口插件http://www.eventghost.org/docs/pluginlist.html)在firefox上触发按键。 Now you have to inject a javascript event handler in the page every time you visit it and most of the work is done. 现在,您每次访问它时都必须在页面中注入一个javascript事件处理程序,并且大部分工作已完成。
Update 2: Here's the basic add-on, ;) have fun 更新2:这是基本的附加组件,;)玩得开心
var self = require('sdk/self');
exports.main = function() {
require('sdk/page-mod').PageMod({
include: '*.org',
contentScript: 'document.onkeypress = function (e) {console.log(e.which);}'
});
}
To use this thing download the cfx-tools from the mozilla site (sorry I can't post more than 2 links) follow the first tutorial ( be sure to read how to use the cfx tools) and when you're ready use the code I posted above. 要使用此功能,请从mozilla网站下载cfx-tools(对不起,我不能发布2个以上的链接),请按照第一个教程进行操作(一定要阅读如何使用cfx工具),并在准备好使用代码时我在上面发布了。
Last suggestion: 最后建议:
document.onkeypress = function (e) { if(e.which == 49){ /* trigger my function if I press 1*/}}
Bye 再见
OK ! 好 ! I finally created an AutoHotkey script and Chrome because : 我终于创建了AutoHotkey脚本和Chrome,因为:
Here's how the script manages a channel change request : 脚本如何管理频道更改请求:
I don't paste the script here because it's long and Stack Overflow code parser really don't like AutoHotkey code ! 我不在此粘贴脚本,因为脚本很长,而且Stack Overflow代码解析器确实不喜欢AutoHotkey代码! Just ask if you want it. 只是问你是否想要。
@EdoPut suggestion is way cleaner, but it didn't solved the focus problem when Flash went full screen. @EdoPut的建议更加简洁,但是当Flash进入全屏模式时,它并没有解决焦点问题。 Anyway thanks again EdoPut for your efforts. 无论如何,再次感谢EdoPut的努力。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.