禁用UIWebView中的超链接 [英] Disable hyperlinks in UIWebView

查看:109
本文介绍了禁用UIWebView中的超链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在加载初始页面后禁用UIWebVIew中的超链接,而不禁用滚动功能。也就是说,我应该启用用户交互。

I want to disable hyperlinks in UIWebVIew after the initial page loaded without disabling the scrolling feature. That is, I should have user interaction enabled.

推荐答案

您可以使用 webView shouldStartLoadWithRequest 喜欢这样:

    (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;
    {

            NSURL *loadURL = [[request URL]retain];
            //change next line to whatever condition you need, e.g.
            //[[loadURL relativeString]  ....] contains a certain substring 
            //or starts with certain letter or ...
            if([[loadURL scheme] isEqualToString: @"file"])
            {
               [loadURL release]; 
            return TRUE;
            }
            [loadURL release];
            return FALSE;
    }

您还必须将webViews委托设置为类的对象,此方法是实现在: [webView setDelegate:my ...];

You also have to set the webViews delegate an object of class where this method is implemented in: [webView setDelegate:my...];

通过上面的实现,没有加载url除了条件为真的那些。至少对于第一个网站的网址来说,它必须是真实的。上面的代码适用于最初加载文件内容的Web视图,仅包含指向http://或https://或...的链接。

By the implementation above, no url is loaded except those for which the condition is true. At least for the url of the first site it has to be true. The code above works for a web view initially loaded with contents of a file, containing only links to 'http://' or 'https://' or ...

这篇关于禁用UIWebView中的超链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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