You can host a web page in a WPF application using the WebBrowser controls that was added in .NET 3.5 SP1:
<Grid>
<WebBrowser Name="browser" />
</Grid>
And in the code-behind you have to set the Uri to your page and an object (which should be com-visible) that is to be called from the java script:
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
string uri = AppDomain.CurrentDomain.BaseDirectory + "TestPage.html";
this.browser.Navigate(new Uri(uri, UriKind.Absolute));
this.browser.ObjectForScripting = new ScriptingHelper();
}
[ComVisible(true)]
public class ScriptingHelper
{
public void ShowMessage(string message)
{
MessageBox.Show(message);
}
}
}
And finally in your page you must call the code using window.external like below:
<head>
<title></title>
<script type="text/javascript">
function OnClick()
{
var message = "Hello!";
window.external.ShowMessage(message);
}
</script>
</head>
<body>
<a href="#" onclick="OnClick()">Click me</a>
</body>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…