开发者

Dismiss a confirm / alert dialog from a javascript bookmarklet

开发者 https://www.devze.com 2023-03-29 02:44 出处:网络
I want to use a bookmarklet to fill up a form and click the s开发者_JS百科ubmit button on a webpage (I have no control over the webpage content).

I want to use a bookmarklet to fill up a form and click the s开发者_JS百科ubmit 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) ?


If your dialog is an alert dialog (usually, it has OK and Cancel buttons), you could override the confirm() method to always return true, which is what happens when you click OK:

window.confirm = function(){return true;};

If your dialog is an alert dialog (usually, it has only an OK button), you need to override the alert() method to just return nothing (undefined):

window.alert = function(){};

They must be set before the confirm() or alert() methods are called by the webpage.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号