【问题标题】:How to click input type="submit" in newest firefox?如何在最新的 Firefox 中点击 input type="submit"?
【发布时间】:2010-12-28 21:05:02
【问题描述】:

我为 Facebook 制作了非常受欢迎的 UserJS,但从 FF 3.6.13 版本开始它就不起作用(对于那个版本)。我只是不知道如何点击这些元素:

<input value="Accept" type="submit" name="something... asdf" />

?用鼠标点击这些按钮会重定向到另一个页面。

我的脚本所做的是使用 Xpath 搜索此类元素,然后使用简单的 acceptbutton.click(); 来单击它们

它在 Opera、Chrome 和 FF

可能使用 JQuery 的 click() 函数会有所帮助,但我不能在我的 userjs 中使用 jquery。

我也试过acceptbutton.form.submit();,但它会将我重定向到错误的页面。

编辑:

好的,我正在添加代码片段

                 var acceptbuttons = xpath(document,'//label[@class="uiButton uiButtonConfirm"]/input');
        for (var i = 0; i < acceptbuttons.snapshotLength; i++) { 
        //will search for particular accept button
            var acceptbutton = acceptbuttons.snapshotItem(i);
            var acceptbuttonName = acceptbutton.getAttribute("name");

            if(acceptbuttonName.indexOf(urlPart)!=-1)
            {
            // it founds button but function below do nothing in FF
            acceptbutton.click();return;
            }
        }

感谢您的帮助!

【问题讨论】:

  • 一个完整脚本的链接会很好......停止编辑,我已经修复了它;)

标签: javascript firefox input click userjs


【解决方案1】:

可以使用最新版 Firefox 中提交按钮的click() 方法。你还有别的问题。您是否在表单上有阻止点击工作的 onsubmit 事件,或者您有错误的按钮?

我通过在 Firefox 3.6.13 的地址栏中粘贴 javascript: document.getElementById('submit-button').click(); void(0); 来提交此内容。这个想法的功劳在这里:JavaScript auto-POST with NAME

【讨论】:

    【解决方案2】:

    嗯,不会做一个简单的 document.whatever_formname.submit();做这个伎俩?

    【讨论】:

    • 正如我所说,我试过了,但它会将我重定向到与正常点击不同的页面。
    • acceptbutton.form.submit() 对我来说看起来很奇怪......您的表单是否有名称“form”?据我所知,正确的语法是 document.formname.submit()...
    • 我从这个 StackOverflow 问题中得到它:stackoverflow.com/questions/991367/…。该页面有 50 多个表单,它们都没有名称,所以我可以这样称呼它,但我怀疑提交表单是我正在寻找的。我只需要模拟点击那个按钮。
    【解决方案3】:

    如果acceptbutton.form.submit(); 不起作用,因为value="Accept" 部分没有发送,为什么不添加一个隐藏的输入以便它可以发送?

    var hiddenInput = document.createElement('input');
    hiddenInput.type = 'hidden';
    hiddenInput.name = acceptbutton.name;
    hiddenInput.value = acceptbutton.value;
    acceptbutton.form.appendChild(hiddenInput);
    acceptbutton.form.submit();
    

    【讨论】:

    • 和 Booosh 的代码一样。也许它提交了价值,但这不是我想要的,因为它会将我重定向到错误的页面。在其他浏览器中使用普通鼠标单击或 acceptbutton.click() 会将我重定向到可以触发其他脚本功能的新页面。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-09-28
    • 2016-12-07
    • 2013-09-07
    • 1970-01-01
    • 2021-11-23
    • 2015-11-14
    • 1970-01-01
    相关资源
    最近更新 更多