0

In my iPhone app,I am using a web view in a view controller. When I press and hold the screen,some selections come on webview, at times a action sheet comes which has "copy" and "cancel" buttons

How to remove this ?

enter image description here

iPatel
  • 46,010
  • 16
  • 115
  • 137

2 Answers2

3

you can disable the selection by using this code

[webView stringByEvaluatingJavaScriptFromString:@"document.body.style.webkitTouchCallout='none'; document.body.style.KhtmlUserSelect='none'"];

if you using Jscript in your web page then this could do the trick

[webView stringByEvaluatingJavaScriptFromString:@"window.getSelection().removeAllRanges();"];

if you want to disable copy paste then this could do the trick

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender 
{    
    if (action == @selector(copy:) ||
        action == @selector(select:)||
        action == @selector(paste:)||
        action == @selector(cut:)) 
    {
        return NO;
    }
    return [super canPerformAction:action withSender:sender];
}

OR

 webView.userInteractionEnabled=NO; // in case you need to disable whole UIWebView
nsgulliver
  • 12,655
  • 23
  • 43
  • 64
0

If you are using .css, you can add these to the appropriate style

    *.noselect {
            -webkit-user-select:none;
            -webkit-touch-callout:none;
    }
Mike M
  • 4,358
  • 1
  • 28
  • 48