Do the HtmlWindow returned from the HtmlPage.PopupWindow can .Invoke or .Eval javascript
Posted
by Nadzzz
on Stack Overflow
See other posts from Stack Overflow
or by Nadzzz
Published on 2010-05-11T18:08:16Z
Indexed on
2010/05/11
18:14 UTC
Read the original article
Hit count: 385
Creating a separate PopupWindow that opens another web browser give me as return value a HtmlWindow object that is the same object type as the static "HtmlPage.Window" of the silverlight project. That object type provides the "Invoke" and "Eval" methods.
I want to evaluate a javascript that can be located on my Silverlight code in a string value (Eval) or inside the uri that I have popped up (Invoke).
Nomather script execution method I use, It fails. For eval, it gives me an InvalidOperationException with "Eval failed." message. For Invoke, it gives me an InvalidOperationException with "Failed to Invoke: TalkToJavaScript." message.
Is there a way to execute javascript on a PopupWindow.
The code here is a simple test. The first time that I press the button it popup the uri in a new webbrowser instance. The second time that I click, it tries to execute javascript on the destination uri window. It fails at ** "m_window.Invoke("TalkToJavaScript", "pute");"
Html code
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
function TalkToJavaScript(data) {
alert("Message received from Silverlight: " + data);
}
</script>
</head>
<body>
<div id="content" />
</body>
</html>
Silverlight Code
private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
{
if (m_window == null)
{
HtmlPopupWindowOptions options = new HtmlPopupWindowOptions();
options.Left = 0;
options.Top = 0;
options.Width = 800;
options.Height = 600;
m_window = HtmlPage.PopupWindow(new Uri("http://www.visionwww.com/tests/ContentInjectionTest.html"),
"new", options);
}
else
{
m_window.Invoke("TalkToJavaScript", "test");
//m_window.Eval("alert(\"Message received from Silverlight\");");
}
}
© Stack Overflow or respective owner