TheGateKeeper
TheGateKeeper

Reputation: 4530

Capturing javascript popups

In WebBrowser, is there anyway to capture the stupid popups that are generated by javascript?

The ones which say "Success" or watever and have the "Ok" button.

I tried the WebBrowser "NewWindow" event, but this is not being fired.

Any tips?

Upvotes: 1

Views: 190

Answers (2)

Mattias Åslund
Mattias Åslund

Reputation: 3907

I once needed to scrape a website using webbrowser where the site did all sorts of javascript I needed to bypass. My solution that time was to download the url with WebClient, parsing the html as a string and remove all javascript and then set the new html string as the Document of my WebBrowser.

Maybe that is a good approach for you?

Upvotes: 0

Richard
Richard

Reputation: 22016

You could simply redefine the global javascript alert function like this:

function alert() {}

then nothing will happen when other code calls the alert.

UPDATE:

to do this add the following to your page code:

<script>
   function alert() {}
</script>

If you are injecting it to your pages then you may wish to look at greasemonkey and then add this script using that:

https://addons.mozilla.org/en-US/firefox/addon/greasemonkey/

there are similar addons for all browsers.

Upvotes: 2

Related Questions