I would like to create a webview on a windows application.
The problem is that I don't know how to catch an event when a window will open with IE. When a link has target="_blank", windows automatically open IE. I tried to make the application with C# and JS but the issue is the same.

On the JS part, I tried to add an event with 'newwindow' but it doesn't work
For the C# part, I used webview on the XAML and for the HTML I used x-ms-window

The problem with some link is that they have target="_blank" into their tag.

Is their a solution to this problem ? Is their a way to catch those event ?

有帮助吗?

解决方案

Simplest solution will be (using jQuery):

$('a[target=_blank]').on('click',function(e){ 
    e.stopPropagation();
    e.preventDefault();
    window.external.notify($(this).prop('href'));
});

In Windows 8 you must add your page (host) to AllowedScriptNotifyUris

In Windows 8.1 you will probably need to have some other workaround to use window.external.notify as allowed hosts are embedded in app manifest and must be loaded by https

其他提示

Startign on Windows 10, you can use the WebView.NewWindowRequested event:

private void WebView1_NewWindowRequested(
    WebView sender,
    WebViewNewWindowRequestedEventArgs args)
{
    // Prevent the browser from being launched.
    args.Handled = true;

    // Open the Uri in the current window.
    sender.Source = args.Uri;
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top