webbrowser-control

How do I add a local script file to the HTML of a WebBrowser control?

≯℡__Kan透↙ 提交于 2019-11-27 22:19:49
This seems really dumb. I've tried a bunch of different ways and it's just not working. I have a WinForms app with a WebBrowser control. If I try with a raw html file on my desktop using the same src string, the src I put together works fine. But plugging the same stuff into the WebBrowser control won't work. Here's my code: HtmlElementCollection head = this.wbPreview.Document.GetElementsByTagName( "head" ); if (head != null) { HtmlElement elm = this.webBrowserControl.Document.CreateElement("script"); string mySource = Environment.CurrentDirectory + @"\MyScriptFile.js"; elm.SetAttribute("src",

How to update DOM content inside WebBrowser Control in C#?

对着背影说爱祢 提交于 2019-11-27 21:55:34
问题 I've a windows .Net Form which contains a WebBrowser Control. This WebBrowser displays a webpage based on its Url property. Can I modify the DOM of the displayed page inside the WebBrowser control ? If yes, how to ? 回答1: For those who are interested, here's the solution: HtmlElement headElement = webBrowser1.Document.GetElementsByTagName("head")[0]; HtmlElement scriptElement = webBrowser1.Document.CreateElement("script"); IHTMLScriptElement domScriptElement = (IHTMLScriptElement)scriptElement

How to set and delete cookies from WebBrowser Control for arbitrary domains

拜拜、爱过 提交于 2019-11-27 21:33:32
How can I set and delete cookies for a domain in webbrowser control without using Javascript ( which doesn't allow to set / delete cookies without navigating to the website first. ) Managed to accomplish this task by combining these 2: http://support.microsoft.com/kb/815718 and INTERNET_OPTION_END_BROWSER_SESSION - http://msdn.microsoft.com/en-us/library/windows/desktop/aa385328(v=vs.85).aspx Michalis Hope this helps using System.Runtime.InteropServices; namespace Storm8 { class Program { [DllImport("wininet.dll", SetLastError = true)] private static extern bool InternetSetOption(IntPtr

Using WebBrowser in a console application

眉间皱痕 提交于 2019-11-27 21:22:37
I want to use it to invoke some JS scripts on the webpage. I have this: static void Stuff() { WebBrowser browser = new WebBrowser(); browser.Navigate("http://www.iana.org/domains/example/"); HtmlDocument doc = browser.Document; //doc.InvokeScript("someScript"); Console.WriteLine(doc.ToString()); } static void Main(string[] args) { Console.WriteLine("hi"); var t = new Thread(Stuff); t.SetApartmentState(ApartmentState.STA); t.Start(); } Question 1: I get an "object reference not set" exception when I try to get doc.ToString() . Why? Question 2: How do I get some data from the HTML document into

WinForms - How do I execute C# application code from inside WebBrowser control?

拥有回忆 提交于 2019-11-27 20:56:50
I have a form containing a web browser control. This browser control will load some HTML from disk and display it. I want to be able to have a button in the HTML access C# code in my form. For example, a button in the HTML might call the Close() method on the form. Target platform: C# and Windows Forms (any version) Look at the WebBrowser.ObjectForScripting property. Managed to get Google Maps talking to a windows forms application using this. I've implemeted this in a few applications in the past, here's how: (NB: the example below is not production ready and should be used as a guide only).

Windows Forms Webbrowswer control with IDownloadManager

浪尽此生 提交于 2019-11-27 20:16:39
I'm using the Systems.Windows.Forms.Webbrowser control and need to override the download manager. I've followed the instructions here to subclass the form and override CreateWebBrowserSiteBase() /// <summary> /// Browser with download manager /// </summary> public class MyBrowser : WebBrowser { /// <summary> /// Returns a reference to the unmanaged WebBrowser ActiveX control site, /// which you can extend to customize the managed <see ref="T:System.Windows.Forms.WebBrowser"/> control. /// </summary> /// <returns> /// A <see cref="T:System.Windows.Forms.WebBrowser.WebBrowserSite"/> that

WebBrowser control - ignore SSL errors

前提是你 提交于 2019-11-27 19:52:09
Many hours of searching has not lead to an answer. We're looking for a way that a .NET WebBrowser control can navigate to pages with SSL security problems (self-signed certificates or non-matching hostnames) without stopping and displaying the error page: I've already seen many posts that are close: How to disable “Security Alert” window in Webbrowser control -- doesn't work because WebBrowser apparently doesn't use the ServicePointManager Suppressing Hosted WebBrowser Control Dialogs -- depends on knowing window titles, which doesn't work for a non-English audience C# WebBrowser Control -

How to use watin with WebBrowser control?

試著忘記壹切 提交于 2019-11-27 19:13:15
问题 Is there any way which would allow me to use watin's functionalities from my web browser control? simply i want to use watin with my web browser control i don't want my application to open a new window ,i need it in my web browser control. 回答1: If you are using .Net WebBrowser Control you can create WatiN's IE object by using following code: var ie = new IE(webBrowser.ActiveXInstance); But if you do that inside your Form_Load ActiveXInstance will be null. And if you do that for example inside

Handling hardware back button and sending it to WebBrowser control running on Windows Phone

痴心易碎 提交于 2019-11-27 18:43:30
问题 I have a web browser control embedded into a PhoneApplicationPage. I have to handle the hardware back button and force the web browser to go back. I know how to handle hardware back button. How do you force the webbrowser to go to a previous page? The seemingly simple GoBack() and CanGoBack property on WinForms webbrowser seems to be missing on Windows Phone. 回答1: If you enable script on the WebBrowser control by setting IsScriptEnabled="true" you can then use the following to navigate

Using XPath and WebBrowser Control to select multiple nodes

China☆狼群 提交于 2019-11-27 17:02:05
问题 In C# WinForms sample application I have used WebBrowser control and JavaScript-XPath to select single node and change that node .innerHtml by the following code: private void MainForm_Load(object sender, EventArgs e) { webBrowser1.DocumentText = @" <html> <head> <script src=""http://svn.coderepos.org/share/lang/javascript/javascript-xpath/trunk/release/javascript-xpath-latest-cmp.js""></script> </head> <body> <img alt=""0764547763 Product Details"" src=""http://ecx.images-amazon.com/images/I