Search code examples
javascriptiphonecssios4uiwebview

Disable copy and paste in UIWebView


Nearly, I had tried every thing to disable copy/paste in UIWebView but nothing worked with me.

I'm loading my UIWebView from a string (array of strings) as follows:

[webView loadHTMLString:
[NSString stringWithFormat:@"%@<p class=\"paragraph\"  style=\"float: right\"  >%@</p>",css,[[array objectAtIndex:0] valueForKey:@"content"]]   baseURL:nil ];

I had tried this:

-(void)webViewDidFinishLoad:(UIWebView *)webView1{
[webView1 stringByEvaluatingJavaScriptFromString:@"document.body.style.webkitUserSelect='none';"];
}

and this:

  NSString *css =
@"<head><style><body> *{-webkit-touch-callout: none; -webkit-user-select: none;}</style> </head>  </body> ";

but nothing worked with me especially for iOS 4.2


Solution

  • -webkit-user-select: none; /* Disable selection/Copy of UIWebView */
    

    will also disable form on Mobile Safari.