In my application I need to use a WebBrowser control to process user login. I use WPF and it's WebBrowser control. The problem is that I want to display a part of web page that is under certain div. I found a solution to this, I need to inject an javascript script into a loaded html page, but I have no clue how to do it :(
This is the script that I would like to inject into web.
function showHide() {
$('body >').hide();
$('#div').show().prependTo('body');
}
So i could later call it webbrowser1.InvokeScript("showHide");
I read a lot of posts on stack, but all of them refer to WindowsForms WebBrowser and it is not working with WPF one.
EDIT: I tried:
private void PageLoaded (object sender, NavigationEventArgs e)
{
var webBrowser = sender as WebBrowser;
webBrowser.Document.InvokeScript("execScript",
new object[] {"$('body >').hide(); $('#" + _div + "').show().prependTo('body');"});
}
But webBrowser.Document
is type object and I cannot call InvokeScript on it, have no clue to what I should cast it.
Thanks for help.