从 JavaScript 书签中关闭确认/警报对话框
我想使用书签来填写表单并单击网页上的提交按钮(我无法控制网页内容)。 按下提交按钮后,会弹出一个确认框,我必须单击 OK
。最后一步打破了自动化。如何自动关闭书签 (javascript) 中的弹出窗口?
I want to use a bookmarklet to fill up a form and click the submit button on a webpage (I have no control over the webpage content).
After the submit button is pressed, there is a popup confirmation box where I have to click OK
. This last step breaks the automation. How do I automatically dismiss the popup from the bookmarklet (javascript) ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的对话框是警报对话框(通常具有
OK
和Cancel
按钮),您可以重写confirm()
方法以始终返回true,这就是您单击“确定”时发生的情况:如果您的对话框是警报对话框(通常只有一个“确定”按钮),则需要覆盖
>alert()
方法不返回任何内容(undefined
):必须在网页调用
confirm()
或alert()
方法之前设置它们。If your dialog is an alert dialog (usually, it has
OK
andCancel
buttons), you could override theconfirm()
method to always return true, which is what happens when you clickOK
:If your dialog is an alert dialog (usually, it has only an
OK
button), you need to override thealert()
method to just return nothing (undefined
):They must be set before the
confirm()
oralert()
methods are called by the webpage.