首页 > 学院 > 开发设计 > 正文

WKWebView调用window.open(url,"_blank”);没有反应的问题

2019-11-09 17:40:39
字体:
来源:转载
供稿:网友

在使用WKWebView的时候,网页调用window.open(url,"_blank”);发现没有任何响应,也没有调用任何回调,即便写了createWebViewWithConfiguration方法也没用,最终找到原因是没有设置:

PReferences.javaScriptCanOpenWindowsAutomatically = YES;

最终解决的代码:

初始化代码:

WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init];    config.processPool = processPool;    WKPreferences *preferences = [WKPreferences new];    preferences.JavascriptCanOpenWindowsAutomatically = YES;//很重要,如果没有设置这个则不会回调createWebViewWithConfiguration方法,也不会回应window.open()方法    config.preferences = preferences;    self.webView = [[WKWebView alloc] initWithFrame:self.view.bounds configuration:config];    //    self.webView = [[WKWebView alloc] initWithFrame:self.view.bounds];    self.webView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;    self.webView.backgroundColor = [UIColor clearColor];    self.webView.contentMode = UIViewContentModeRedraw;    self.webView.opaque = YES;    [self.view addSubview:self.webView];    [_webView setUserInteractionEnabled:YES];//是否支持交互    _webView.navigationDelegate = self;    _webView.UIDelegate = self;//很重要,如果没有设置这个则不会回调UIDelegate相关所有方法

createWebViewWithConfiguration方法代码:在本Webview打开这个网址

-(WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures{    NSLog(@"createWebViewWithConfiguration  request     %@",navigationAction.request);    if (!navigationAction.targetFrame.isMainFrame) {        [webView loadRequest:navigationAction.request];    }    if (navigationAction.targetFrame == nil) {        [webView loadRequest:navigationAction.request];    }    return nil;}

参考:http://blog.csdn.net/u011619283/article/details/52135982


上一篇:多线程

下一篇:Expandablelistview 简单使用

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表