WPF WebBrowser控件解析 HTML
Window里面的AllowsTransparency属性不要加
新增的css样式不识别
<WebBrowser x:Name="webBrowser" />
public void InitWeb()
{
string htmlString = @"<html>
<head>
<title>this is a test</title>
<script type ='text/javascript'>
function Hello()
{
window.external.Hello('hello test'); // 传递事件
}
</script>
</head>
<body>
<button onclick = 'Hello()'>
hello test
</button>
</body>
</html> ";
webBrowser.NavigateToString(htmlString);
ObjectForScriptingHelper helper = new ObjectForScriptingHelper(this);
webBrowser.ObjectForScripting = helper;
}
[System.Runtime.InteropServices.ComVisibleAttribute(true)]
public class ObjectForScriptingHelper
{
signature mainWindow;
public ObjectForScriptingHelper(signature main)
{
mainWindow = main;
}
public void Hello(string cmd)
{
}
}