[英]How do I get reference to the new window in WebView2?
比如说,我正在点击Flashscore web 网站上的一些网球比赛。 弹出一个新的 window。 我想在 WebView2 中捕获第二个 window:
browser.CoreWebView2Ready += delegate
{
browser.CoreWebView2.NewWindowRequested += OnNewWindowRequested;
};
private async void OnNewWindowRequested(object sender, CoreWebView2NewWindowRequestedEventArgs e)
{
var newWindow = e.NewWindow; //null
}
但是, newWindow
是null
。 同时,使用WindowFeatures
,我可以获得新的 window 的高度或宽度:
uint height = e.WindowFeatures.Height;
uint width = e.WindowFeatures.Width;
如何捕获对第二个 window 的引用?
The NewWindowRequested event can let you cancel opening a new window or replace the window with your own, but you cannot have WebView2 open a new window for you and get a reference to that new window.
NewWindowRequested 事件场景:
Handled
属性设置为true
。 取消新 window 的打开。 如果window.open
是创建新 window 的内容,则返回值为null
。Handled
属性设置为true
,并使用Uri
属性在用户的默认浏览器中打开 URI,或者以其他方式在 WebView2 之外处理新的 window。Handled
属性设置为true
,并将NewWindow
属性设置为您创建的新 CoreWebView2。 如果window.open
是创建新 window 的内容,则返回值是新的 window ZA8CFDE6331BD59EB66AC96F8911 对应于 CoreWebView2。 您可以通过从 CoreWebView2Environment class 创建一个新的 CoreWebView2 来获取新的 CoreWebView2,或者如果您在 WPF、WinForms 或 WinUI 中使用 WebView2 元素,您可以创建一个新的 WebView2 元素并使用其 CoreWebView2 属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.