<small id='ZYmey'></small><noframes id='ZYmey'>

    <tfoot id='ZYmey'></tfoot>
  1. <legend id='ZYmey'><style id='ZYmey'><dir id='ZYmey'><q id='ZYmey'></q></dir></style></legend>
      <i id='ZYmey'><tr id='ZYmey'><dt id='ZYmey'><q id='ZYmey'><span id='ZYmey'><b id='ZYmey'><form id='ZYmey'><ins id='ZYmey'></ins><ul id='ZYmey'></ul><sub id='ZYmey'></sub></form><legend id='ZYmey'></legend><bdo id='ZYmey'><pre id='ZYmey'><center id='ZYmey'></center></pre></bdo></b><th id='ZYmey'></th></span></q></dt></tr></i><div id='ZYmey'><tfoot id='ZYmey'></tfoot><dl id='ZYmey'><fieldset id='ZYmey'></fieldset></dl></div>

      • <bdo id='ZYmey'></bdo><ul id='ZYmey'></ul>

      如何可靠地检测 UIWebView 中的链接点击?

      How can I reliably detect a link click in UIWebView?(如何可靠地检测 UIWebView 中的链接点击?)

      <small id='Bi909'></small><noframes id='Bi909'>

          <legend id='Bi909'><style id='Bi909'><dir id='Bi909'><q id='Bi909'></q></dir></style></legend>
              <tbody id='Bi909'></tbody>
              <tfoot id='Bi909'></tfoot>

            • <i id='Bi909'><tr id='Bi909'><dt id='Bi909'><q id='Bi909'><span id='Bi909'><b id='Bi909'><form id='Bi909'><ins id='Bi909'></ins><ul id='Bi909'></ul><sub id='Bi909'></sub></form><legend id='Bi909'></legend><bdo id='Bi909'><pre id='Bi909'><center id='Bi909'></center></pre></bdo></b><th id='Bi909'></th></span></q></dt></tr></i><div id='Bi909'><tfoot id='Bi909'></tfoot><dl id='Bi909'><fieldset id='Bi909'></fieldset></dl></div>
              • <bdo id='Bi909'></bdo><ul id='Bi909'></ul>

                本文介绍了如何可靠地检测 UIWebView 中的链接点击?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我有一个 UIWebView,当用户点击链接时我需要做一些事情.有一个委托回调可用于检测点击:

                I have a UIWebView and I need to do something when user taps a link. There’s a delegate callback that can be used to detect the taps:

                - (BOOL) webView: (UIWebView*) webView
                    shouldStartLoadWithRequest: (NSURLRequest*) request
                    navigationType: (UIWebViewNavigationType) navigationType
                {
                    if (navigationType == UIWebViewNavigationTypeLinkClicked) {
                        …
                    }
                }
                

                问题是这段代码不能处理所有的链接点击.例如,一个普通的 Google 搜索结果页面对链接做了一些奇怪的事情:

                The problem is that this code doesn’t handle all link clicks. As an example, a plain Google Search results page does something weird with the links:

                <a href="http://example.com/" class="l" onmousedown="return rwt(…)">
                    <em>Link Text</em>
                </a>
                

                rwt 函数导致链接在点击时不会触发 UIWebViewNavigationTypeLinkClicked 事件.有没有办法可靠地检测落入导航到其他页面"存储桶的所有事件?

                The rwt function results in the links not triggering the UIWebViewNavigationTypeLinkClicked event when tapped. Is there a way to reliably detect all events that fall into the "navigate to some other page" bucket?

                推荐答案

                到目前为止,我已经得出以下解决方案.首先,我在加载时将一些 JS 代码注入到页面中:

                So far I have arrived at the following solution. First, I inject some JS code into the page when loaded:

                function reportBackToObjectiveC(string)
                {
                    var iframe = document.createElement("iframe");
                    iframe.setAttribute("src", "callback://" + string);
                    document.documentElement.appendChild(iframe);
                    iframe.parentNode.removeChild(iframe);
                    iframe = null;
                }
                
                var links = document.getElementsByTagName("a");
                for (var i=0; i<links.length; i++) {
                    links[i].addEventListener("click", function() {
                        reportBackToObjectiveC("link-clicked");
                    }, true);
                }
                

                当用户点击链接时,由于 webView:shouldStartLoadWithRequest: navigationType: 委托调用,我提前知道了:

                When user taps a link, I know it in advance thanks to the webView:shouldStartLoadWithRequest: navigationType: delegate call:

                if ([[[request URL] scheme] isEqualToString:@"callback"]) {
                    [self setNavigationLeavingCurrentPage:YES];
                    return NO;
                }
                

                然后,如果另一个请求来了并且 _navigationLeavingCurrentPage 为真,我知道用户点击了一个链接,即使导航类型标志是 UIWebViewNavigationTypeOther.我仍然需要对解决方案进行广泛的测试,因为我担心它会导致一些误报.

                Then if another request comes and _navigationLeavingCurrentPage is true, I know the user has clicked a link even though the navigation type flag is UIWebViewNavigationTypeOther. I still have to test the solution extensively, for I’m afraid that it will lead to some false positives.

                这篇关于如何可靠地检测 UIWebView 中的链接点击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                EAAccessory/EASession teardown during background(EAAccessory/EASession 在后台拆除)
                Getting an NSArray of a single attribute from an NSArray(从 NSArray 获取单个属性的 NSArray)
                ImageIO: lt;ERRORgt; JPEG Corrupt JPEG data: premature end of data segment iphone - how to catch this?(ImageIO:lt;错误gt;JPEG 损坏的 JPEG 数据:iphone 数据段过早结束 - 如何捕捉到这个?)
                How to get indexPath.row of tableView which is currently being displayed?(如何获取当前正在显示的 tableView 的 indexPath.row?)
                Xcode iOS organizer submit to app store yields quot;The archive is invalidquot; error(Xcode iOS 管理器提交到应用商店产生“存档无效;错误)
                MFMessageComposeViewController alloc returns nil(MFMessageComposeViewController alloc 返回 nil)

                  <small id='X6SHQ'></small><noframes id='X6SHQ'>

                      <bdo id='X6SHQ'></bdo><ul id='X6SHQ'></ul>

                    • <legend id='X6SHQ'><style id='X6SHQ'><dir id='X6SHQ'><q id='X6SHQ'></q></dir></style></legend>
                        <tfoot id='X6SHQ'></tfoot>

                          <tbody id='X6SHQ'></tbody>

                        1. <i id='X6SHQ'><tr id='X6SHQ'><dt id='X6SHQ'><q id='X6SHQ'><span id='X6SHQ'><b id='X6SHQ'><form id='X6SHQ'><ins id='X6SHQ'></ins><ul id='X6SHQ'></ul><sub id='X6SHQ'></sub></form><legend id='X6SHQ'></legend><bdo id='X6SHQ'><pre id='X6SHQ'><center id='X6SHQ'></center></pre></bdo></b><th id='X6SHQ'></th></span></q></dt></tr></i><div id='X6SHQ'><tfoot id='X6SHQ'></tfoot><dl id='X6SHQ'><fieldset id='X6SHQ'></fieldset></dl></div>