Is it possible to call JS code before a page loads (or before other javascript code is called on the page)? For example: Using webbrowser control, I navigate to “http://google.com”, but before any js code on google is executed, I’d like to do something like “alert(‘one moment!’);”.
Any ideas as to how I can accomplish this? I’d guess that I have to somehow modify the html before it fully loads, add the js function, then execute it using invokescript, but not sure how I’d go about that.
My first suggestion is to use scripts inside the
<head> tag:You could use jQuery:
Or:
In any case you have to make a special effort not to do this kind of things. It’s a very bad practice, especially if it involves user interaction.