当用户单击附加小部件时,我想在加载的页面上实现这一点:
var e = jQuery.Event("keydown", { keyCode: 405 });
$("input").trigger(e);
jQuery 已经加载到目标页面中。我试过这个:
var widgets = require("widget");
var tabs = require("tabs");
var pageMod = require("page-mod");
var widget = widgets.Widget({
id: "button-test",
label: "button-test",
contentURL: "http://www.mozilla.org/favicon.ico",
onClick: function() {
tabs.activeTab.attach({
contentScript:
'var e = window.jQuery.Event("keydown", { keyCode: 405 }); $("input").trigger(e);'
});
}
});
我在控制台中收到以下错误:
Timestamp: 30/08/2012 14:06:36
Error: An exception occurred.
Traceback (most recent call last):
File "javascript:var e = window.jQuery.Event("keydown", { keyCode: 405 }); $("input").trigger(e);", line 1, in
TypeError: window.jQuery is undefined
我需要 postMessage 还是 port.emit()?我也试过 jQuery.event (没有窗口)