Dismiss a confirm / alert dialog from a javascript bookmarklet
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.
精彩评论