使用Javascript单击给定的按钮并将其在新窗口中打开
Using Javascript to click on a given button AND have it open in a new window
当这个页面加载时,我想模拟在新窗口(或新标签页)中打开时自动单击send me this thing
按钮
- 在任何这样的页面上都只有一个
send me this thing
按钮
为什么?
这是针对 Fluid.app 上的Greasekit的,类似于Greasemonkey。
该按钮是一个链接,该页面使用 jQuery。 因此,您可以获得以下按钮:
var buyItBtn = $("a:contains('Send me this thing')");
然后修改链接以在新选项卡/窗口中打开。
然后单击链接。
代码为:
//-- Note that :contains() is case-sensitive.
var buyItBtn = $("a:contains('Send me this thing')");
buyItBtn.attr ("target", "_blank");
buyItBtn[0].click ();
但是,请注意现代弹出窗口阻止程序会阻止这一点,我不知道您的 Fluid 版本中嵌入的 webkit 是什么。 告诉您的弹出窗口阻止程序允许这些特定的弹出窗口。
另外,因为这是 Greasekit,所以你需要注入上面的代码,所以完整的用户脚本将是这样的:
// ==UserScript==
// @name _Amazon-like store, buy things in a new window
// @include https://dl.dropboxusercontent.com/u/5546881/*
// @grant GM_addStyle
// ==/UserScript==
/*- The @grant directive is needed to work around a design change
introduced in GM 1.0. It restores the sandbox.
*/
function GM_main () {
//-- Note that :contains() is case-sensitive.
var buyItBtn = $("a:contains('Send me this thing')");
buyItBtn.attr ("target", "_blank");
buyItBtn[0].click ();
}
addJS_Node (null, null, GM_main);
function addJS_Node (text, s_URL, funcToRun, runOnLoad) {
var D = document;
var scriptNode = D.createElement ('script');
if (runOnLoad) {
scriptNode.addEventListener ("load", runOnLoad, false);
}
scriptNode.type = "text/javascript";
if (text) scriptNode.textContent = text;
if (s_URL) scriptNode.src = s_URL;
if (funcToRun) scriptNode.textContent = '(' + funcToRun.toString() + ')()';
var targ = D.getElementsByTagName ('head')[0] || D.body || D.documentElement;
targ.appendChild (scriptNode);
}
相关文章:
- 防止Iframe窗体在新窗口中打开
- 如何在新选项卡中而不是在新窗口中打开URL
- 为在新窗口中打开外部链接创建异常
- SVG编辑链接获胜't在新窗口中打开
- 如何将数据传递给 jsp 并从 servlet 在新窗口中打开它
- 将坐标传递到HTML页面以在新窗口中打开谷歌街景
- ASP.Net电子邮件有一个超链接应该在新窗口中打开
- 如何在新窗口中打开url
- 在新窗口中打开时,未在画布中绘制图像
- 如何在新窗口中打开打印
- 使用javascript在新窗口中打开重定向操作
- AngularJS-使用ng-click在新窗口中打开链接
- 在新窗口中打开DIV按钮
- 使用Javascript单击给定的按钮并将其在新窗口中打开
- Javascript:尝试在新窗口中打开表单提交按钮,链接由单选按钮确定
- asp.net按钮类型链接应该在新窗口中打开
- 我需要隐藏'在新窗口中打开'当我使用Iframe打开我的页面时,谷歌查看器中的按钮
- HTML-使用按钮在新窗口中打开本地PDF
- 按钮在新窗口中打开链接
- 用于在新窗口中打开网页的HTML基本按钮代码