美文网首页
WKWebview 加载URL 点击无法跳转问题

WKWebview 加载URL 点击无法跳转问题

作者: 朵朵一花浪 | 来源:发表于2019-09-30 09:33 被阅读0次

    解决 WKWebview 加载URL 点击无法跳转问题

        WKPreferences *preference = [[WKPreferences alloc]init];
        //最小字体大小 当将javaScriptEnabled属性设置为NO时,可以看到明显的效果
        preference.minimumFontSize = 0;
        //设置是否支持javaScript 默认是支持的
        preference.javaScriptEnabled = YES;
        // 在iOS上默认为NO,表示是否允许不经过用户交互由javaScript自动打开窗口
        preference.javaScriptCanOpenWindowsAutomatically = YES;
        config.preferences = preference;
        
        // 是使用h5的视频播放器在线播放, 还是使用原生播放器全屏播放
        config.allowsInlineMediaPlayback = YES;
        //设置视频是否需要用户手动播放  设置为NO则会允许自动播放
        config.mediaTypesRequiringUserActionForPlayback = YES;
        
        self.wkWebView = [[WKWebView alloc]initWithFrame:CGRectMake(0, 0, 0, 0) configuration:config];
    

    需要设置 javaScriptCanOpenWindowsAutomatically 为YES 解决该问题
    还有一种问题按钮无响应,HTML中打开新的窗口带有blank下面这种方式可解决,实现 WKUIDelegate 方法

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

    相关文章

      网友评论

          本文标题:WKWebview 加载URL 点击无法跳转问题

          本文链接:https://www.haomeiwen.com/subject/xkjavftx.html