Replies: 6 comments
-
It does not use window.open, please use Add host object |
Beta Was this translation helpful? Give feedback.
-
Its working for us, Add Host Object, sample below //Browse Host initialize during webview2 initialize
//Call back from web to .net application
In HTML
Hope this helps |
Beta Was this translation helpful? Give feedback.
-
@vmeganathan81 This page1. html is not my own page and I have no control over the content of this page. As soon as I open page1. html, window.open is automatically executed and page2.html is opened. |
Beta Was this translation helpful? Give feedback.
-
You need to handle the CoreWebView2.NewWindowRequested event. By default without handling that event, new windows are opened in mini-browser-like windows. The end user can interact with these windows but the end developer cannot. If you would like to interact with that should handle the event. You have several options which I have examples of in new window sample code switch (NewWindowBehaviorComboBox.SelectedIndex)
{
// Open mini browser window
case 0:
// Default behavior. No change to args required.
break;
// Send to default browser
case 1:
args.Handled = true;
// No need to wait for the launcher to finish sending the URI to the browser
// before we allow the WebView2 in our app to continue.
_ = Windows.System.Launcher.LaunchUriAsync(new Uri(args.Uri));
break;
// Navigate in same WebView2
case 2:
args.Handled = true;
args.NewWindow = sender;
break;
// Open in different WebView2
case 3:
args.Handled = true;
using (args.GetDeferral())
{
await WebView2Right.EnsureCoreWebView2Async();
args.NewWindow = WebView2Right.CoreWebView2;
}
break;
// Ignore
case 4:
args.Handled = true;
break;
} If you want handle the new window request in a different WebView2 control, you'll need to write app code to create a new WebView2. The sample above just uses an already created WebView2Right member. But for another application you might want to open a new app window and create a WebView2 in that window. |
Beta Was this translation helpful? Give feedback.
-
david-risney |
Beta Was this translation helpful? Give feedback.
-
The sample is a XAML app and the WebView2Right and the combo box are defined in the XAML. For WinForms it will be very similar: you'll use a different WebView2 or create a new WebView2 control. |
Beta Was this translation helpful? Give feedback.
-
My Winform application uses WebView2,
When I open page1.html in WebView2, the page1.html code looks like this:
I use window.open in pag1.html to open a page page2.html,,the page2.html code looks like this:
But how do I control page2.html,
I want to do something with page2.html injection JS
Beta Was this translation helpful? Give feedback.
All reactions