当我点击wkWebView中的弹出窗口时,我会通过获得该操作
- (nullable WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures{
if (!navigationAction.targetFrame.isMainFrame) {
//[webView loadRequest:navigationAction.request];
[self showInternalWeb:navigationAction.request.URL.absoluteString];
}
return nil;
}
以及在不同的控制器中显示该链接。
我想在窗户关闭时自动关闭那个控制器。在我的笔记本电脑浏览器中,按下新窗口上的按钮后,控制器会自动关闭。我想知道自己是如何编写此功能的。
我试过打电话:
[userContentController addScriptMessageHandler:self name:@"window.close()"];
[self.webView evaluateJavaScript:@"window.close()" completionHandler:^(id _Nullable obj, NSError * _Nullable error) {
NSLog(@"suces");
}];
这会正常调用webViewDidClose,但在窗口变为空白时不会调用。
请检查,是否为webView设置了UIDelegate。。
webView.UIDelegate = self;