可可:WKWebView / WebView无法打开Gmail或收件箱内的链接 [英] Cocoa: WKWebView / WebView cannot open links inside Gmail or Inbox

查看:94
本文介绍了可可:WKWebView / WebView无法打开Gmail或收件箱内的链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Boxy 的开发人员,Boxy是Gmail围绕Inbox的著名本地包装程序,想问问是否有人能够从开发的第一天开始就一直为我提供帮助。



这是问题所在: inbox.google.com上的链接 gmail.com 的工作方式与其他网站上的工作方式不同:点击它们不会触发我的webview上的导航操作(我我正在专门使用 WKWebView ,但是使用旧的 WebView 也会出现此问题。因此,我很难在适当的时候在外部浏览器中打开链接。



因此,在撰写本文时,我依赖于要打开链接,请执行以下操作:使用JavaScript(使用事件侦听器)拦截 document.body 的点击,然后通过调用本机应用程序迫使它们在外部浏览器上打开。 / p>

我最好的猜测是,Gmail /收件箱应用程序执行一些JavaScript魔术操作是为了跟踪对电子邮件中所有链接的点击,并且以某种方式干扰



是否有人知道如何解决此问题?



我已经尝试过的东西




  • 实现方法 -webView:createWebViewWithConfiguration:forNavigationAction:windowFeatures: WKUIDelegate 。无效:调用该方法,但与导航操作关联的请求为空。


解决方案

我找到了解决方案。此问题是由于单击链接而不是使用target = _blank打开而导致的,Gmail尝试打开about:blank窗口,然后运行javascript重定向链接。
您需要确保Gmail可以正确接收所创建窗口的句柄。

 -(WKWebView *) webView:(WebUI *)webView 
createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration
forNavigationAction:(WKNavigationAction *)navigationAction
windowFeatures:(WKWindowFeatures *)windowFeatures

您需要确保此委托方法正确返回新创建的wkwebview。


I am the developer of Boxy, a famous native wrapper around Inbox by Gmail, and wanted to ask if anyone is able to help with something I have been struggling with since day one of development.

Here is the problem: links on inbox.google.com and gmail.com work differently than on other sites: clicking on them does not trigger a navigation action on my webview (I am using a WKWebView specifically, but the problem is also present using the old WebView). So I am having a difficult time opening links in an external browser when appropriate.

Because of this, at the time of this writing, I am relying on a terrible hack in order to open links: intercepting clicks on the document.body with javascript (using an event listener) and then forcing them to open on the external browser by calling the native app.

My best guess is that the Gmail/Inbox apps perform some javascript magic in order to track clicks on all the links inside emails and that, somehow, this interfers with the standard behaviour.

Has anyone got any idea how I can solve this problem?

Things I already tried

  • Implementing the method -webView:createWebViewWithConfiguration:forNavigationAction:windowFeatures: of WKUIDelegate. Did not work: the method is called but the request associated with the navigation action is empty.

解决方案

I found a solution. This issue is due to when clicking link, instead of opening using target=_blank, Gmail attempts to open an about:blank window and then run javascript to redirect the link. You need to make sure that Gmail can correctly receive the handle of the created window.

- (WKWebView *)webView:(WebUI *)webView
createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration
forNavigationAction:(WKNavigationAction *)navigationAction
windowFeatures:(WKWindowFeatures *)windowFeatures

You need to make sure this delegate method correctly returns the newly created wkwebview.

这篇关于可可:WKWebView / WebView无法打开Gmail或收件箱内的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆