views:

194

answers:

1

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"&gt;
<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\");");
        }
    }
A: 

Your is not XAP also being served from "http://www.visionwww.com/". Hence when you attempt to manipulate it with an Invoke that attempt is blocked for security reasons.

AnthonyWJones