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>]
static member HostScript : obj
static member HostScript : obj
Public Shared ReadOnly Property HostScript As 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) 檔中的 window 物件

如果框架從跨定義域位置巡覽至 ,則 HostScript 屬性會 null 傳回 。

您可以藉由設定 ScriptInteropDisallow 登錄值,關閉 Internet Explorer 的這項功能。 如需詳細資訊,請參閱 安全性 (WPF)

適用於