In a browser extension, how do I click a specific button of an alert?
So...
I need to click [Stay on this page]
automatically in such a prompt:
Confirm navigation: [Leave this page] [Stay on this page]
The code that invokes this is
$(w开发者_如何学编程indow).bind('beforeunload', function() {
return 'Leave page?';
//Click prompt code goes here.
$(window).unbind();
});
If I take away return 'Leave page?';
then the iframed page overrides the top frame and the user is struck with an unknown site, maybe there's another way to do this?
Actually that would hook into the onbeforeunload
event:
$(window).bind('beforeunload', function() {
return 'Leave page?';
});
Instead of automatically clicking it, check if you can automatically disable window.onbeforeunload
event handlers. That's most likely much easier than trying to send a click to a specific button in a modal window anyway.
I agree with Thiefmaster. Alternative is to replace the alert, prompt or confirm if that is what is used:
window.confirm=function() {
// here you do what you want
}
精彩评论