- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to inject JavaScript in WebBrowser control?
To inject JavaScript in WebBrowser control, use the following steps −
- Firstly, create a Windows Forms application in Visual Studio.
- Now, drag a WebBrowser control to the form
- Set the Url property.
- Right-click the project, choose to Add reference... → COM → Type Libraries
- Select "Microsoft HTML Object Library"
Add the following code to inject JavaScript.
private void myWebBrowser(object sender, WebBrowserDocumentCompletedEventArgs e){ // head element HtmlElement hElement = weBrowser.Document.GetElementsByTagName("head")[0]; // script element HtmlElement sElement = weBrowser.Document.CreateElement("script"); IHTMLScriptElement val = (IHTMLScriptElement)sElement.DomElement; element.text = "function sayHello() { alert('Weclome') }"; hElement.AppendChild(sElement); weBrowser.Document.InvokeScript("How you doing?"); }
- Related Articles
- How to put the WebBrowser control into IE9 into standards with HTML?
- How to use labels to control the Flow in JavaScript?
- Difference between @Inject and @Autowired
- How can we inject the service dependency into the controller C# Asp.net Core?
- How to control automated window resizing in Tkinter?
- How to Control Common Bus in Computer Architecture?
- How to control recursion in Get-ChildItem in PowerShell?
- How to define control flow statements in JShell in Java 9?
- How to Control YouTube Recommendations on your Channel?
- Explain how CO2 is able to control fires.
- Control how letters are spaced in CSS
- How we can control fire?
- How to control serialization through @JSON annotation using flexjson in Java?
- How to control the border of a bar patch in matplotlib?
- How to turn mobile into a universal remote control?

Advertisements