Compartir a través de


WebBrowser.NavigateToString Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Displays the specified HTML content.

Namespace:  System.Windows.Controls
Assembly:  System.Windows (in System.Windows.dll)

Syntax

'Declaration
Public Sub NavigateToString ( _
    text As String _
)
public void NavigateToString(
    string text
)

Parameters

Remarks

The text parameter should be formatted as HTML. The text parameter can also contain JavaScript. If there are JavaScript functions contained in the HTML, you can use the InvokeScript method to call the functions from managed code. For security reasons, you should never display user-provided, and therefore untrusted, HTML using the NavigateToString method.

Examples

The following example shows how to use the NavigateToString method to display cross-domain content in an <iframe>.

Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
    WB1.NavigateToString("<html><head></head><body>Silverlight Developer Site" & _
        "<iframe src=""https://www.silverlight.net"" WIDTH=300 HEIGHT=200>" & _
            "</iframe></body></html>")
End Sub
private void Button_Click(object sender, RoutedEventArgs e)
{
    WB1.NavigateToString("<html><head></head><body>Silverlight Developer Site" +
    "<iframe src=\"https://www.silverlight.net\" WIDTH=300 HEIGHT=200>" + 
        "</iframe></body></html>");
}
    <StackPanel>
    <Button Width="200" Content="Click for Silverlight.net" Click="Button_Click"  />
    <WebBrowser Height="270" Width="400" x:Name="WB1" />
</StackPanel>

Version Information

Silverlight

Supported in: 5, 4

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.