WPF WebBrowser control and JavaScript window.open parameters - c#

I've got a WPF application and have a window that contains a System.Windows.Controls.WebBrowser control. I've wired up events like DWebBrowserEvents2_NewWindow2EventHandler, DWebBrowserEvents2_ProgressChangeEventHandler, DWebBrowserEvents2_NavigateComplete2EventHandler, etc.
Opening popup windows using NewWindow2 or NewWindow3 is OK, but I'd really like to be able to respect and implement the underlying window.open() call's features parameter, like the third parameter here:
var newWindow = window.open('http://www.foo.com','myWindow', 'left=20,top=20,width=500,height=500,toolbar=1,resizable=0');
I've read this question and answer, and gone on a 2-day all-out search of the web for a simple(ish) implementation, but all I've really found is the csexwb2 project, which seems like overkill to me. I don't want to totally replace the WebBrowser control with something else. I'd just like to, at a minimum, open popups at the correct size, as specified by the window.open() call.
I simply can't find a simple, decent, complete implementation of INewWindowManager::EvaluateNewWindow using a WebBrowser control in C#. Hasn't anybody had to implement this? I'm stumped.

Related

Awesomium webcontrol

So I've been trying to use something other than IE for my webcontrol in a side-project of mine (C#, WPF project type) and I was looking around for alternatives and have tried in the past but failed to implement them.
I decided to try again and implement awesomium, however it is still confusing as always and doesn't have any straight forward examples for me to use as a base.
Would someone be able to show me how to implement awesomium for a webview/webcontrol? My vision is to have it navigate to a shoutbox website, and while my application is still open to keep it there (i.e not refresh it so that it doesn't lose anything) as it is being shown in the space of tabitem.
I have used Awesomium, but the last version I used was 1.6.1, and there are some differences between that and the current version - they've actually made things easier.
The documentation says that you should be able to force navigation of the control simply by setting the Source property:
<osm:WebControl Name="webControl"
Source="http://www.google.com/"
/>
If you find the Source property is not bindable then simply revert to using some code behind in the view - subscribe to a property change event from the viewmodel (or from an event broker if you are using one), and change the Source property in response to an event.
I believe, the problem with the Source property is that if you are setting it to the same URI to refresh, it won't refresh because of a bug. It is documented on their github page and their answers page.
As workaround, to refresh your page correctly you need to pass a fake URI first and then your page again to your binding property, like this:
CurrentSource = "FakeUriString".ToUri();
CurrentSource = "http://www.yourpage.com".ToUri();
Keep in mind, my current version of Awesomium is 1.7.4.2 and they may fix this issue in the future as they stated in their issues page.

How can I open a webpage first and then fill in text boxes and click a button and visibly view the results?

[edit] It is a requirement that the webpage spawn and open in IE and allow user manual interaction after the programmatic actions have completed.[/edit]
I've seen a lot of code examples online about opening webpages or filling in webpage textboxes and getting a return value without ever opening them visibly.
I would like to open a webpage in IE, fill in a few textbox buttons
and then click the submit button and view the results visibly.
I am able to do this with a dll called Selenium, but I do not want to use a 3rd party application and it seems that WebBrowser() should be able to do this?
I can post my failed code examples if that would help.
Thanks.
Maybe this qould fit better as a comment, but I don't have enoigh reputation.
Do you know how HTTP-Forms work?
It would probably be easier to send a HTTP-Request to the target of the form you want to fill, including the parameters you would like to fill into the form.
So you don't need any WebBrowser or similar, just a simple HttpWebRequest object, where you specity the target, the method (very likely POST) and the data you'd like to send.
You can use the webbrowser control in Winforms. It is possible to access every DOM object of the website using the control. No need to open the IE externally.
You just need to specify the webbrowser URL as your link.
Then, fill the textboxes with code,
BrowserID.Document.GetElementById("TextboxID").SetAttribute("Value", "NewVaue")
Also, you can click on the button using InvokeMember("click").
There are lots of stuff using WebBrowser. You can learn it here.

Windows Phone browser live html modification

I haven't looked into it very much but am struggling to find relevant information on the topic. I basically want to create a browser that applies a filter to a webpage by changing colors in a webpage. My guess is that I will have to change the html once loaded or something, would this work? Do I have other options?
PS. I don't just want to make every color darker, I would more like to invert the colors.
Edit:
If any you were wondering, I am talking about the XAML browser component that can be used in a Windows Phone application.
I think the simplest way to do that is to inject some Javascript into your page once it has loaded.
To do that, you need to set the IsScriptEnabled to true on your WebBrowser control and then subscribe to the Navigated event.
When that event occurs you can inject some JS codeby using the WebBrowser.InvokeScript method.
Here is an example of JS code that darken the page : JavaScript: Invert color on all elements of a page
If you are talking about in a PC internet browser, you can find an add-on to execute Javascript automatically, such as Greasemonkey for Firefox. If you are talking about Windows Phone's Internet Explorer, I don't really know what you could do there, as I don't think they allow add-ons.

WebBrowser control inside IE

I have a .NET ActiveX/COM Object which has a WebBrowser control (among other controls such has buttons, etc) inside it.
This object seems to load fine, the buttons are displayed and working but, for some reason, the WebBrowser control doesn't show up!
Is there some limitation for this in IE (e.g., is IE afraid of something recursive, etc.)? Is there a way that I can overcome it?
Thanks in advance,
Zubrowka
FireBreath has a library called WebView that does this; I've tested it both in NPAPI based browsers and in ActiveX and it works just fine. There are many reasons why you may want to do this.
Since I don't know what you're doing, I can't tell you what you're doing wrong... but I can show you the source code that FireBreath uses to do it:
https://github.com/firebreath/FireBreath/blob/master/src/libs/WebView/Win/WebViewWin.cpp
This is in C++, but you might be able to find something useful from it. I don't use .net in the browser -- too much overhead -- but theoretically the same principles should apply.

Curious pop-up behavior when using WebBrowser class

My C# application includes an embedded web browser, which is made possible by the System.Windows.Forms.WebBrowser class. Users are able to navigate to websites using the app, however, when they encounter a page that includes a pop-up window, the pop-up window is opened by Internet Explorer.
Does anyone know how to suppress that behavior?
NOTE: I'm new to C#, so please take that into consideration when responding.
Are you looking to actively block popups or handle them in your application? If you're wanting to customize the blocking, then you'll have to implement the DWebBrowserEvents2 interface, specifically the NewWindow3 method. NewWindow3 method has specific functionality for blocking window popups (i.e. setting the Cancel parameter to true). These methods will also let you show your own window if you wish, though you'll have to provide your own Form to host yet another WebBrowser.
If you'd like to see some real C# source code providing advanced functionality with the WebBrowser control, I'd have to say that this article on CodeProject provided almost everything I know about the WebBrowser control. Be sure to download the source!
#Kramii is correct that you can also use the NewWindow2 event to prevent the popup. NewWindow3 provides additional parameters for if you're looking to inspect the URL or other data about the navigate to actually sometimes block and sometimes handle the popup yourself.
IIRC you can trap the NewWindow2 event on the WebBrowser control and set Cancel = true to prevent the pop-up.
This article may help:
http://www.codeproject.com/KB/cpp/ExtendedWebBrowser.aspx#GoalBlock

Categories

Resources