-api-id | -api-type |
---|---|
E:Windows.UI.Xaml.Controls.WebView.NewWindowRequested |
winrt event |
Occurs when a user performs an action in a WebView that causes content to be opened in a new window.
<WebView NewWindowRequested="eventhandler"/>
See WebViewNewWindowRequestedEventArgs.
This event occurs only for user initiated actions. By default, when a user clicks a link in a WebView that requests to open in a new window, the link launches the default browser. A new window can be caused by the user clicking on an href, or a button which calls window.open.
Handle this event to provide custom handling of the new window request. You might navigate the WebView to the desired page, or create a new WebView in your app to display the requested content. If you provide custom handling of the new window request, set the Handled property to true to prevent the default browser from being launched.
<WebView x:Name="myWebView" NewWindowRequested="OnNewWindowRequested" />
private void OnNewWindowRequested (WebView sender, WebViewNewWindowRequestedEventArgs e)
{
if (e.Referrer.Host == "www.contoso.com")
{
var newWebView = new WebView();
newWebView.Navigate(e.Uri);
myGrid.Children.Add(newWebView);
e.Handled = true;
}
}