如何将 parent.postMessage("Hello from child window", "*") 消息捕获到 child
How to catch the parent.postMessage("Hello from child window", "*") message into child
如何在 Xaml 代码后面(Parent window)捕获消息?我的 child window 正在抛出此消息
在childwindow,
function sendMsg() {
var status = document.getElementById("status");
if (parent && parent.postMessage) {
parent.postMessage("Hello from child window", "*");
status.innerText = "Sent message to parent...";
}
}
在Parentwindow(xaml.cs),
private void button1_Click(object sender, RoutedEventArgs e)
{
// Get URI to navigate to
Uri uri = new Uri("child window url to be opened");
// Navigate to the desired URL by calling the .Navigate method
this.mybrowser.Navigate(uri);
}
在Xaml,
<WebBrowser Name="mybrowser" Margin="339,10,10,10" Height="396"></WebBrowser>
<Button Content="Send Message to WebView" Margin="10,-700,736,0" Height="20" Click="Button_Click"/>
最后我使用 java 脚本的 window.external 方法和 ObjectForScriptingHelper class.If 我在 class ObjectForScriptingHelper class.Create 中有一个 InvokeMeFromJavascript 方法此 class 的对象并将其传递给 WebBrowser control.This 的 属性 ObjectForScripting 有详细说明
http://www.dotnetfunda.com/articles/show/840/working-with-webbrowser-in-wpf
如何在 Xaml 代码后面(Parent window)捕获消息?我的 child window 正在抛出此消息
在childwindow,
function sendMsg() {
var status = document.getElementById("status");
if (parent && parent.postMessage) {
parent.postMessage("Hello from child window", "*");
status.innerText = "Sent message to parent...";
}
}
在Parentwindow(xaml.cs),
private void button1_Click(object sender, RoutedEventArgs e)
{
// Get URI to navigate to
Uri uri = new Uri("child window url to be opened");
// Navigate to the desired URL by calling the .Navigate method
this.mybrowser.Navigate(uri);
}
在Xaml,
<WebBrowser Name="mybrowser" Margin="339,10,10,10" Height="396"></WebBrowser>
<Button Content="Send Message to WebView" Margin="10,-700,736,0" Height="20" Click="Button_Click"/>
最后我使用 java 脚本的 window.external 方法和 ObjectForScriptingHelper class.If 我在 class ObjectForScriptingHelper class.Create 中有一个 InvokeMeFromJavascript 方法此 class 的对象并将其传递给 WebBrowser control.This 的 属性 ObjectForScripting 有详细说明 http://www.dotnetfunda.com/articles/show/840/working-with-webbrowser-in-wpf