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打开新窗口的问题。

  • 相关阅读:
    01背包问题需要找出相应路径
    单链表的正序输出和逆序输出
    二叉树之叶子节点个数
    01背包问题
    STL之map和multimap(关联容器)
    python的tips:字符和字符串的问题
    postman的使用(转载)
    python tips(3);import的机制
    python每日一类(5):itertools模块
    python每日一类(4):slice
  • 原文地址:https://www.cnblogs.com/shenyuiOS/p/14747411.html
Copyright © 2011-2022 走看看