Share via


BrowserInteropHelper.HostScript Propriété

Définition

Obtient un objet de script qui fournit l’accès à l’objet de fenêtre HTML, aux fonctions de script personnalisées et aux variables globales pour la page HTML, si l’application de navigateur XAML (XBAP) est hébergée dans un cadre.

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

Valeur de propriété

Objet de script qui fournit l’accès à l’objet de fenêtre HTML, aux fonctions de script personnalisées et aux variables globales pour la page HTML, si l’application de navigateur XAML (XBAP) est hébergée dans un cadre ; sinon, null.

Attributs

Exemples

L’exemple suivant montre comment récupérer l’objet HostScript et fermer la fenêtre du navigateur.

<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

Remarques

Avec l’objet retourné HostScript , vous pouvez accéder aux propriétés, méthodes et événements de l’objet de fenêtre HTML, appeler une fonction de script directement ou accéder à une variable globale. La syntaxe permettant d’accéder à ces éléments utilise la notation par points familière.

Pour plus d’informations sur l’objet window, consultez Window.

La HostScript propriété retourne null si l’image est parcourue à partir d’un emplacement inter-domaines.

Cette fonctionnalité peut être désactivée pour le navigateur en définissant la valeur de Registre ScriptInteropDisallow . Pour plus d’informations, consultez Sécurité (WPF).

S’applique à