BrowserInteropHelper.HostScript Property

Definition

Gets a script object that provides access to the HTML window object, custom script functions, and global variables for the HTML page, if the XAML browser application (XBAP) is hosted in a frame.

public:
 static property System::Object ^ HostScript { System::Object ^ get(); };
public static dynamic HostScript { [System.Security.SecurityCritical] [System.Security.SecurityTreatAsSafe] get; }
public static dynamic HostScript { get; }
[<get: System.Security.SecurityCritical>]
[<get: System.Security.SecurityTreatAsSafe>]
static member HostScript : obj
static member HostScript : obj
Public Shared ReadOnly Property HostScript As Object

Property Value

A script object that provides access to the HTML window object, custom script functions, and global variables for the HTML page, if the XAML browser application (XBAP) is hosted in a frame; otherwise, null.

Attributes

Examples

The following example demonstrates how to retrieve the HostScript object and close the browser window.

<Grid>
   <Button Width="160" Height="60" Click="Button_Click" Content="Close Browser Window" />
 </Grid>
private void Button_Click(object sender, RoutedEventArgs e)
{
    // Retrieve the script object. The XBAP must be hosted in a frame or
    // the HostScript object will be null.
    var scriptObject = BrowserInteropHelper.HostScript;

    // Call close to close the browser window. 
    scriptObject.Close();
}
Private Sub Button_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
    ' Retrieve the script object  The XBAP must be hosted in a frame or
    ' the HostScript object will be null.
    Dim scriptObject = BrowserInteropHelper.HostScript

    ' Call close to close the browser window.
    scriptObject.Close()
End Sub

Remarks

With the returned HostScript object, you can access the properties, methods, and events of the HTML window object, call a script function directly, or access a global variable. The syntax to access these items uses the familiar dot notation.

For more information about the window object, see Window.

The HostScript property returns null if the frame is navigated to from a cross-domain location.

This feature can be turned off for the browser by setting the ScriptInteropDisallow registry value. For more information, see Security (WPF).

Applies to