Disable hyperlinks in UIWebView

夙愿已清 提交于 2019-12-02 05:26:20

问题


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.


回答1:


You can work with webView shouldStartLoadWithRequest like this:

    (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;
    }

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

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 ...



来源:https://stackoverflow.com/questions/1783074/disable-hyperlinks-in-uiwebview

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!