简体   繁体   English

使用Firefox SDK在非活动标签中的div上调用click()事件

[英]Calling a click() event on a div in an inactive tab using the Firefox sdk

I am trying to write a Firefox Addon using the Firefox SDK. 我正在尝试使用Firefox SDK编写Firefox插件。 I want to call click() on a div in an inactive tab when a user clicks on a button in my Addon panel. 当用户单击“我的插件”面板中的按钮时,我想在非活动选项卡中的div上单击click()。 I already have the tab variable but now I'm just not sure if it's possible to simulate a click on this tab which is not the active tab. 我已经有了tab变量,但是现在我不确定是否可以模拟对此选项卡(不是活动选项卡)的单击。

For example, when the tab is active, I go into the console and type: 例如,当选项卡处于活动状态时,我进入控制台并键入:

$("#div_id").click()

How can I call such a function when that tab isn't currently active? 当该选项卡当前不活动时,如何调用该函数?

My code in my main.js function: 我在main.js函数中的代码:

var data = require("sdk/self").data;
var tabs = require("sdk/tabs");
var self = require("sdk/self");

var control_tab = require("sdk/panel").Panel({
  width: 212,
  height: 200,
  contentURL: data.url("control-tab.html"),
  contentScriptFile: data.url("get-buttons.js")
});


require("sdk/widget").Widget({
  label: "Control Tab",
  id: "control-tab",
  contentURL: "http://www.mozilla.org/favicon.ico",
  panel: control_tab
});

control_tab.port.on("bind_now", function onBind() {
  var bound_Tab = tabs.activeTab;
});

control_tab.port.on("next", function onNext() {
//enter click() event here on bound_Tab
});

Assume you have 假设你有

<input type=hidden id=someID value=true name=someName/>

Then: 然后:

$("#b1").bind("click", function(){

$("#someId").attr("value", "false");

});

Then: 然后:

Call document.getElementById() and get this element .And call its functions 调用document.getElementById()并获取此元素并调用其函数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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