BrowserInteropHelper.HostScript Property

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.

Namespace:  System.Windows.Interop
Assembly:  PresentationFramework (in PresentationFramework.dll)

'Declaration
Public Shared ReadOnly Property HostScript As Object

Property Value

Type: System.Object
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, Nothing.

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 object in the Dynamic HTML (DHTML) documentation.

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

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

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

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
<Grid>
   <Button Width="160" Height="60" Click="Button_Click" Content="Close Browser Window" />
 </Grid>

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4

.NET Framework Client Profile

Supported in: 4

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft