Compartilhar via


WebBrowser.ScriptNotify Event

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Occurs when the content contained in the WebBrowser control passes a string to the Silverlight plug-in by using JavaScript.

Namespace:  System.Windows.Controls
Assembly:  System.Windows (in System.Windows.dll)

Syntax

'Declaration
Public Event ScriptNotify As EventHandler(Of NotifyEventArgs)
public event EventHandler<NotifyEventArgs> ScriptNotify
<WebBrowser ScriptNotify="eventHandler"/>

Remarks

The Silverlight hosting environment allows you to call Notify on the Window.external object and pass a string to the plug-in. When you do this, the ScriptNotify event occurs.

This is an asynchronous event.

For more information about handling events, see Events Overview for Silverlight.

Examples

The following example shows how to handle the ScriptNotify event. In this example, the InvokeScript is called, which in turn calls the LoadSearch function in the following HTML. The HTML file must be hosted in the same domain as the Silverlight application. The JavaScript within the HTML page calls window.external.notify, which raises the ScriptNotify event in the Silverlight application.

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title></title>
    <script type="text/javascript" >
    function LoadSearch(searchString) {
        window.location = "https://www.bing.com/search?q=" + searchString
        window.external.notify("Search completed")
     }
     </script>
 </head>
<body>
Silverlight WebBrowser control.
</body>
</html>
Partial Public Class MainPage
    Inherits UserControl
    Public Sub New()
        InitializeComponent()
    End Sub

    Private Sub WB1_ScriptNotify(ByVal sender As Object, ByVal e As NotifyEventArgs)
        Button1.Content = e.Value

        Button1.IsEnabled = False
    End Sub

    Private Sub Button1_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
        Dim results As Object = WB1.InvokeScript("LoadSearch", New String() {"Silverlight"})
    End Sub
End Class
public partial class MainPage : UserControl
{
    public MainPage()
    {
        InitializeComponent();
    }

    void WB1_ScriptNotify(object sender, NotifyEventArgs e)
    {
        Button1.Content = e.Value;
        Button1.IsEnabled = false;

    }

    private void Button1_Click(object sender, RoutedEventArgs e)
    {
        object results = WB1.InvokeScript("LoadSearch", new string[] { "Silverlight" });
    }
}
<StackPanel x:Name="LayoutRoot" Height="358" Width="489" Background="LightBlue">
    <WebBrowser  x:Name="WB1" Source="https://localhost/HTMLPage1.htm" Height="272" Width="379" 
                 ScriptNotify="WB1_ScriptNotify" Margin="5" />
    <Button Width="200" x:Name="Button1" Content="Click to search!" Click="Button1_Click" />
</StackPanel>

Version Information

Silverlight

Supported in: 5, 4

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.