Click here to Skip to main content
15,907,395 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I added a web browser control and navigates to the url I want.

I'd like to simulate clicking on a link. However, that link runs a javascript.
What happens when I click it, is that internet explorer opens up the link, instead of it opening in my windows forms.

What I have tried:

I've tried 
wb.Document.InvokeScript("javascript_procedure_name") but this also opens up internet explorer.
Updated 8-Jul-21 0:39am

Share this answer
jsc42 7-Jul-21 12:14pm    
This is definitely true for HyperText Markup Applications and used to be true for embedded web in forms, but I do not know if it is still true for Windows forms ...
Web browsers in forms run using an old HTML DLL which equates to MS-IE7 (HTML3 + CSS2 + JavaScript1.3).
Shoshana Michel 7-Jul-21 12:48pm    
I see that the javascript is doing to go to a new page in a different window.
Handle the control's NewWindow event, cancel it, and display the URL in your own form instead.

WebBrowser.NewWindow Event (System.Windows.Forms) | Microsoft Docs[^]

NB: The WebBrowser control is extremely limited. By default, it will be stuck in IE7-mode, which means many websites will break. You may want to use a more modern control instead - for example:
Microsoft Edge WebView2 Control - Microsoft Edge Development | Microsoft Docs[^]
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900