I use a webbrowser control in my application to get data from a specific web page. This web page won't work with the older IE because it specifically checks for the IE version. So I made a registry change that allows my application to work as IE 9 and everything is ok most of the time...
The problem is when a newwindow has to be opened. It won't display anything. I guess that the newwindow is acknowledged as IE 7 and I don't know how to make it disguise itself as IE9.
I also tried the other way round. I thought that if I intercepted the newwindow url then I could just send it to IE9 or open it in another instance of a webbrowser control. But the newwindow event only allows to cancel the event. You can't get any useful information out of it.
I believe that interop services is what I need but I know nothing about them.
So I've got two questions:
(1) Can I make the newwindow identify as IE9? (and how...)
(2) How can I get the newwindow url using interop services (or anything, I wouldn't care)?
It is quite strange (from my perspective) that the WebBrowser control doesn't surface the much-more-useful NewWindow3 event.
This CodeProject article describes a remarkably simple way to make it available.
In the NewWindow event, assuming your first Wb control is named WB1 and the one you want to redirect to is WB2, do the following in your WB1 NW event.
Processed = True ' This cancels the current request.
WB2.Navigate URL ' This redirects it to the second WB2 control.
Otherwise, if you want to use the NW2 (NewWindow2) event instead of the NewWindow (NW) event, do this in the NW2 event of the WB1 control.
Set ppDisp = WB2.object ' Just swaps the objects around to redirect, don't need to issue a cancel.
Also, you can do this via BeforeNavigate2 (of WB1). But slightly different code.
Cancel = True ' Cancel Request.
WB2.Navigate2 URL ' Reissue it to WB2.
Now, as long as you control where it redirects to, you can get the new window URL easily, using WB2.LocationURL or Wb2.Document.URL if i am not mistaken.
Also, if you want to change the rendering engine to IE9 (even if IE9 is installed on your computer, WB control will use IE7 rendering engine for compatibility)... there are articles online and answers on SO (including some of my previous answers) which clarify how you can alter the registry to ensure the rendering engine used by the WB control is the same as that of the installed version (IE9), otherwise, it will always use IE7. And, if you have IE4, 5 or 6 installed on a machine, it will always use IE4 for the rendering engine. I think they update teh rendering version after ever 3-4 version changes. I'm assuming during version 10, WB control rendering version will be version 10 as well.
Let me know if you need more assistance with it and i've love to know how you got along and if this helped answer your question. All my examples are in VB6, but you can transform them easily.
Cheers.
Related
This might be a simple question, but I have a winforms app that is loading a ChromiumWebBrowser control (CefSharp) and I can't figure out how to capture key preview events as they are all being swallowed by the control.
The standard attaching a handler to the PreviewKeyDown event of the browser control isn't working. Is there a known workaround?
CEF is run in it's own message loop, so the standard events don't work.
The first an easiest option is to implement IKeyboardHandler, you can check the CefSharp source for a more detailed example (there's one that forwards messages to the parent window if required).
Second run with settings.MultiThreadedMessageLoop = false, and call Cef.DoMessageLoopWork() on application idle, this will integrate CEF into the same message loop as your main application. Again, the source contains examples see https://github.com/cefsharp/CefSharp/blob/cefsharp/49/CefSharp.WinForms.Example/Program.cs#L63
The third option is to hook into the CEF message loop, see https://github.com/cefsharp/CefSharp/blob/cefsharp/49/CefSharp.WinForms.Example/ChromeWidgetMessageInterceptor.cs for an example
CEF = Chromium Embedded Framework - CefSharp is just a wrapper.
I'm trying to run an webpage inside a Webbrowser control wich contains a connection to an Websocket. The control can't connect to the Websocket.
When I tested in IE, everything runs ok, but in the Webbrowser control inside Visual Studio, the page can't connect to the Websocket.
I tried other pages that contains script to detect browser support for Websockets, when it runs in IE, the page show that Websocket runs with success, but when I'm try to run the same page on Webbrowser control, the page says that webcontrol can't run. How can I do to solve this problem?
Very thank you.
The problem is that the webbrowser control, while using the local IE as a basis, is more locked down (or maybe better to say "differently configured") by default.
The ability to control this is called Feature Control and you can read about it on MSDN here
In terms of solving your actual problems, a similar question has been solved with code provided in this answer to an equivalent question on C#. Note the tweaks in the subsequent answer as well.
I have a C# application which uses a System.Windows.Forms.WebBrowser.
The problem is: i'd like the user to navigate smoothly in my application, without prompts, without javascript windows popping up, without security prompts. Even if this requires some contents to be unavailable.
I just want to have one window (always one window, if a receive a new window event, i redirect it to the single window).
How can i do this?
I tried to use this.browser.ScriptErrorsSuppressed = true but i doesnt seem to work.
For example, if i test it on a browser page which performs text validation, i still receive a popup window saying that my text is invalid.
Thank you!
I've found a solution somewhere else, since it wasn't available here.
Here it is: http://www.codeproject.com/Articles/31163/Suppressing-Hosted-WebBrowser-Control-Dialogs
Basically, you have to hook the WM_INITDIALOG message.
It works wonders here.
I've been writing an ActiveX plugin for IE using .NET. While I've happily got it to deploy, install and what not, I'm finding that IE isn't passing keyboard events to it.
Is there a way to get IE to pass along keyboard events to it?
This problem has been seen to happen on IE7 and IE8, haven't tested other versions of IE though, mainly because I'm using IE8 and the customer will be using IE7.
Thanks in advance.
Edit:
In this case the particular keys I'm interested in are the delete key and the end key
This is a problem with how the browser loads and exposes the object.
As a security measure, some objects will not be activated, until clicked on, and then receive keyboard input.
I actually found a solution Using JavaScript, to pass the characters to the ActiveX Object, so that you do not have to click on it first, to activate it.
I used it for a bar code scanning solution, as there was no keyboard or mouse attached to the device.
Silver light out of browser mode, made the keyboard input available straight away, and became a better solution. Not sure if the latest version still allows it.
I'm trying to use the web browser control to open a url and get its HTML contents. You might ask why I'm not using the System.Net objects, the web pages are formatted through java scripts so the web browser control is the faster way but I can't seem to make it work. First, WebBrowser.Navigate won't fire when called. Please help.
BTW, I wrapped the web browser control from a class in a control library. Does web browser needs to be in a windows form type of assembly? I'm guessing that it has something to do with the message pump -- but I don't know completely. I also tried to house it in a form but still failed. Anyone's help is very much appreciated. I hope Jon Skeet can say something on this :).
Navigate is a method not an event, which event are you expecting to fire?
Yes the browser control expects a parent (otherwise it will have problems like this).
Since the browser control is also an STA component, it also expect a message pump (e.g. Application.Run( new FormMain() or formMain.ShowDialog()) in the current thread to raise events from the background thread.
See also
BUG: DocumentComplete Does Not Fire When WebBrowser Is Not Visible