Masking floating point exceptions with Set8087CW, SetMXCSR and TWebBrowser

Assuming that you have no need for floating point exceptions to be unmasked in your application code, far and away the simplest thing to do is to mask exceptions at some point in your initialization code. The best way to do this is as so: SetExceptionMask(exAllArithmeticExceptions); This will set the 8087 control word on 32 … Read more

How to getelement by class?

There is nothing built-in in the WebBrowser control to retrieve an element by class name. Since you know it is going to be an a element the best you can do is get all a elements and search for the one you want: var links = webBrowser1.Document.GetElementsByTagName(“a”); foreach (HtmlElement link in links) { if (link.GetAttribute(“className”) … Read more

Download a file through the WebBrowser control

Add a SaveFileDialog control to your form, then add the following code on your WebBrowser’s Navigating event: private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e) { if (e.Url.Segments[e.Url.Segments.Length – 1].EndsWith(“.pdf”)) { e.Cancel = true; string filepath = null; saveFileDialog1.FileName = e.Url.Segments[e.Url.Segments.Length – 1]; if (saveFileDialog1.ShowDialog() == DialogResult.OK) { filepath = saveFileDialog1.FileName; WebClient client = new WebClient(); client.DownloadFileCompleted … Read more

WebBrowser control and JavaScript errors

What I would do is assign an object to webbrowser.ObjectForScripting and then inject a javascript function that assigns windown.onerror to a wrapper that calls the external script in the host app. Like: window.onerror = function(message, url, lineNumber) { window.external.errorHandler(message, url, lineNumber); } Refere to: http://notions.okuda.ca/2009/06/11/calling-javascript-in-a-webbrowser-control-from-c/