WebViewControlNewWindowRequestedEventArgs.NewWindow 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
在要求 WebViewControl
內提供新的 WebViewControl
作為腳本呼叫的目標 window.open
。 目標 Webview 中的內容一律會被視為跨原始來源至 opener webview 中的內容,反之亦然,並受限於跨原始來源限制。 屬性 WebViewControl
中 NewWindow
提供的 必須是新的 ,在與開啟程式 Web 檢視相同的進程中執行,而且無法巡覽。 NewWindow
設定屬性的優先順序高於 Handled
屬性。 如果 NewWindow
已設定,則會使用提供的 WebViewControl
。 如果未 NewWindow
設定 ,則會 Handled
檢查以判斷新視窗要求的行為。
public:
property IWebViewControl ^ NewWindow { IWebViewControl ^ get(); void set(IWebViewControl ^ value); };
IWebViewControl NewWindow();
void NewWindow(IWebViewControl value);
public IWebViewControl NewWindow { get; set; }
var iWebViewControl = webViewControlNewWindowRequestedEventArgs.newWindow;
webViewControlNewWindowRequestedEventArgs.newWindow = iWebViewControl;
Public Property NewWindow As IWebViewControl
屬性值
Windows 需求
裝置系列 |
Windows 10, version 1809 (已於 10.0.17763.0 引進)
|
API contract |
Windows.Foundation.UniversalApiContract (已於 v7.0 引進)
|
範例
下列 C# 範例示範允許 window.open 建立傳回給開啟器的新 WebViewControl:
WebViewControlProcess wvProc;
WebViewControl webView;
void OnWebViewControlNewWindowRequested(WebViewControl sender, WebViewControlNewWindowRequestedEventArgs args)
{
if (args.Uri.Domain == “mydomain.com”)
{
using deferral = args.GetDeferral();
args.NewWindow = await wvProc.CreateWebViewControlAsync(
parentWindow, targetWebViewBounds);
deferral.Complete();
}
else
{
// Prevent WebView from launching in the default browser.
args.Handled = true;
}
}
String htmlContent = “<html><script>window.open(‘http://mydomain.com’)</script><body></body></html>”;
webView.NavigateToString(htmlContent);