BrowserInteropHelper.HostScript プロパティ

定義

XAML ブラウザー アプリケーション (XBAP) がフレームでホストされている場合に、HTML ウィンドウ オブジェクト、カスタム スクリプト関数、および HTML ページのグローバル変数へのアクセスを提供するスクリプト オブジェクトを取得します。

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>]
member this.HostScript : obj
member this.HostScript : obj
Public Shared ReadOnly Property HostScript As Object

プロパティ値

Object

XAML ブラウザー アプリケーション (XBAP) がフレームでホストされている場合、HTML ウィンドウ オブジェクト、カスタム スクリプト関数、および HTML ページのグローバル変数へのアクセスを提供するスクリプト オブジェクト。それ以外の場合は . null

属性

次の例では、オブジェクトを取得してブラウザー ウィンドウを HostScript 閉じる方法を示します。

<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

注釈

返された HostScript オブジェクトを使用すると、HTML ウィンドウ オブジェクトのプロパティ、メソッド、イベントにアクセスしたり、スクリプト関数を直接呼び出したり、グローバル変数にアクセスしたりできます。 これらの項目にアクセスするための構文では、使い慣れたドット表記を使用します。

ウィンドウ オブジェクトの詳細については、動的 HTML (DHTML) ドキュメントの ウィンドウ オブジェクト を参照してください。

このプロパティは HostScriptnull クロスドメインの場所からフレームに移動した場合に返されます。

この機能は、 ScriptInteropDisallow レジストリ値を設定することで、Internet Explorer でオフにすることができます。 詳細については、「 セキュリティ (WPF)」を参照してください。

適用対象