Removing hyper links from a URL shown in UIWebView

后端 未结 2 1648
梦如初夏
梦如初夏 2021-01-07 14:56

I am making an app which has a section for latest company news. Basically the plan was initially to use ASIHTTPRequest to extract all the HTML, search through it for tags t

2条回答
  •  伪装坚强ぢ
    2021-01-07 15:27

    OK, setting the UIDataDetectorTypeNone for dataDetectorTypes, should prevent the webview from detecting the links, this is correct.

    Furthermore using the

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

    UIWebview delegate, you can simply return NO for the URL's you don't want the user to allow following...

    Furthermore, you can insert custom CSS Rules, after the page has finished loading in the

    - (void)webViewDidFinishLoad:(UIWebView *)webView 
    

    delegate method, this way:

    [MywebView stringByEvaluatingJavaScriptFromString:@"document.styleSheets[0].addRule(\"a.link\", \"color:#FF0000\")"];
    

    So based on the CSS from the thread I mentioned, this should work:

    [MywebView stringByEvaluatingJavaScriptFromString:@"document.styleSheets[0].addRule(\".active\", \"pointer-events: none;\");document.styleSheets[0].addRule(\".active\", \"cursor: default;\")"];
    

提交回复
热议问题