Disable interaction on UIWebView, only link clickable?

2.3k views Asked by At

i am adding UIWebview in tableview for showing text and link , but not able to scroll tableview, Any way to disable user interaction in webview only click event enable.

Webview have static content not load from web

NSString * htmlString = [NSString stringWithFormat:@"<html><head><script> document.ontouchmove = function(event) { if (document.body.scrollHeight == document.body.clientHeight) event.preventDefault(); } </script><style type='text/css'>* { margin:0; padding:0;} p { color:white; font-family:HelveticaNeue-CondensedBold; font-size:24px;} a { color:#63B604; text-decoration:underline; }</style></head><body><p>%@</p></body></html>", @"search in http://google.com"];

Thanks

2

There are 2 answers

2
Kanhaiya Sharma On

just disable scrolling or using this methods

- (void)webViewDidFinishLoad:(UIWebView *)webView {
    // Disable user selection
    [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitUserSelect='none';"];
    // Disable callout
    [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitTouchCallout='none';"];
}

and open link as follow using delagate methods

-(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType {
    if ( inType == UIWebViewNavigationTypeLinkClicked ) {
        NSURL *url = [inRequest URL];
        if ([[url absoluteString] rangeOfString:@"gmail"].location == NSNotFound) {
            [[UIApplication sharedApplication] openURL:[inRequest URL]];
            return NO;
        }
    }
    return YES;
}
0
B.S. On

Try to disable scrolling in your WebView

[myWebView.scrollView setScrollEnabled:NO]; 
[myWebView.scrollView setBounces:NO];