Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I can embed this url http://www.staff.oma.be/StaffBox.jsp[^] in a webpage through an iframe. With the correct post through a form, I can control this webpage (eg another time window for the graph, another plot, etc ...).

This works in a normal browser, but when I want to use the WebBrowser control in WPF it starts throwing javascript errors all around the place and the frame remains empty (visual), yet the view source, shows the code correctly. Looks like a security issue, but can't find where to correct this.

* searched google, with multiple keywords/sentences
* added <!-- saved from url=(0014)about:internet -->\n\r, but no progress.
* copied the iframe source from the WebBrowser control and saved as html and opened this in a browser => works.


Hopefully someone has an idea.
thanks.

(Visual Studio 2012, .Net 4.5)




[SOLUTION]
* Installed .Net 4.5.2
* Installed CefSharp.Wpf through nuget
* Used that control instead of WebBrowser control in XAML
* added following lines in code
C#
cwb_staffboxes.GetBrowser().MainFrame.LoadStringForUrl(html.ToString(), "http://www.localstaff.be");
cwb_staffboxes.WebBrowser.Load("http://www.localstaff.be");


Note: the http://www.localstaff.be is a dummy url.
[/SOLUTION]

What I have tried:

XAML
<WebBrowser Name="wb_staffboxes" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />

Code behind:
wb_staffboxes.NavigateToString(html.ToString());

html.ToString() yields:
This works in a normal browser, but not in the WebControl of WPF.
HTML
<html><body><iframe id='sb_sw' name='sb_sw' width='700' height='500'></iframe>
<div style="visibility:hidden">
<form id="sendpost" method="post" action="http://www.staff.oma.be/StaffBox.jsp">
<input type="text" id="txtbox_dtsstart" name="txtbox_dtsstart" value="20150318000000" />
<input type="text" id="txtbox_dtsend" name="txtbox_dtsend"  value="20150319000000" />
<input type="text" id="txtbox_plottypes" name="txtbox_plottypes"  value="acespeed|ql;" />
<input type="text" id="txtbox_ticksize" name="txtbox_ticksize" value="2" />
<input type="text" id="txtbox_connectdots" name="txtbox_connectdots" value="true" />
<input type="text" id="txtbox_size" name="txtbox_size" value="640;480" />
</form></div><script>document.getElementById("sendpost").target="sb_sw";
document.getElementById("sendpost").submit();</script>
</body></html>
Posted
Updated 26-Jun-17 2:02am
v3
Comments
jimmson 26-Jun-17 6:49am    
Hi, do you have to use built-in WPF WebBrowser or not?
V. 26-Jun-17 6:49am    
Yes:
<WebBrowser Name="wb_staffboxes" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />

Sorry if that was not clear
jimmson 26-Jun-17 6:52am    
Sorry to hear that! Built-in WPF browser is quite broken (by my opinion) but there are free alternatives you could use instead.
jimmson 26-Jun-17 8:38am    
Well, CefSharp is actually what I wanted to recommend you, till you wrote you need a classic built-in webbrowser. :) Good to hear you resolved it though.
Richard Deeming 26-Jun-17 11:16am    
As you've discovered, the WebBrowser control is locked to IE7 mode by default. You can override it by editing the registry, but you have to do that on every machine where your application runs.

Web Browser Control & Specifying the IE Version | Rick Strahl[^]

CefSharp is a much better solution. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900