I used Offscreen browser. Then, I created webView
, subscribed to DocumentReady
and loaded html.
_originalWebView = WebCore.CreateWebView(this.ViewWidth, this.ViewHeight, WebViewType.Offscreen);
_originalWebView.DocumentReady += browser_DocumentReady;
_originalWebView.LoadHTML(html);
My method for DocumentReady
:
private void browser_DocumentReady(object sender, DocumentReadyEventArgs e)
{
var webView = sender as WebView;
if (webView == null)
return;
if (e.ReadyState == DocumentReadyState.Ready)
return;
var global = e.Environment;
if (!global)
return;
webView.ExecuteJavascript(@"
document.getElementById('id').innerHTML = 'Hello World' ;
");
Thread.Sleep(2000);
if (webView.GetLastError() != Error.None)
System.Diagnostics.Debug.Print("There was an error calling this synchronous method");
Html = _originalWebView.HTML;
webView.Dispose();
}
My html:
<html>
<head>
<title>Example</title>
<meta http-equiv='Content-Type' content='text/html;charset=UTF-8'>
</head>
<body>
<div id='id'>old value</div>
</body>
</html>
And this javascript didn't work. What did I do wrong?
I can did it to execute js only if js was in html. I used Awesomium 1.7.5.
Help me, please :(
This problem was solved when i replaced
Html = _originalWebView.HTML;
on
Html = webView.ExecuteJavascriptWithResult("document.getElementsByTagName('html')[0].innerHTML");