zoukankan      html  css  js  c++  java
  • WKWebView新窗口打开链接

    最近客户说在App中点击链接打不开页面,安卓的可以iOS不行,对于这个问题,设置wkwebview即可

    点击打开测试链接

    1. 需要监听WKUIDelegate中的代理方法,webView:createWebViewWithConfiguration:forNavigationAction:windowFeatures:,代理方法会在webview中的新窗口打开时调用

      - (WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures {
          if (navigationAction.request.URL) {
              [self.webView loadRequest:[NSURLRequest requestWithURL:navigationAction.request.URL]];
          }
          return nil;
      }
      

      解决了新窗口打开的问题

    2. 以为已经没问题了,谁知道测试说有新的问题,上面测试连接中的开始阅读没反应,查看详情可以点击。查看网页源代码,发现开始阅读是调了接口的,在请求完成时用window.open(./xxx)新窗口中打开,而查看详情是直接拼接的url。刚开始因为是接口的问题,想着怎么自己写个页面测试一下,后来在地铁上查到了另外一个方法

      WKPreferences *preferences = [[WKPreferences alloc] init];
      preferences.javaScriptCanOpenWindowsAutomatically = YES;
      config.preferences = preferences;
      

      设置javaScriptCanOpenWindowsAutomatically属性允许js打开新窗口

    完美解决WKWebView打开新窗口的问题。

  • 相关阅读:
    MySQL8.0.x免安装配置
    Java中锁的实现与内存语义
    并发中的volatile
    「LOJ #2163」「POI2011」Tree Rotations
    「CodeChef REBXOR」Nikitosh and xor
    「Codeforces 429D」Destiny
    「Luogu P2042」「NOI2005」维护数列
    「SPOJ SEQ」 Recursive Sequence
    「GCJ 2008 Round 1A C」numbers
    「LOJ #6016」崂山白花蛇草水
  • 原文地址:https://www.cnblogs.com/shenyuiOS/p/14747411.html
Copyright © 2011-2022 走看看