Disabling User Selection in Uiwebview

Disabling user selection in UIWebView

Here are a few ways to disable selection:

Add the following to your mobile web documents

<style type="text/css">
* {
-webkit-touch-callout: none;
-webkit-user-select: none; /* Disable selection/copy in UIWebView */
}
</style>

Programmatically load the following Javascript code:

NSString * jsCallBack = @"window.getSelection().removeAllRanges();";    
[webView stringByEvaluatingJavaScriptFromString:jsCallBack];

Disable the Copy / Paste user menu:

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

How to disable copy share option while selecting text in uiwebview? But selecting text should work

The first thing you need to do is add new class with subclass of UIWEBVIEW.

Paste this code in .m file of your class.

@implementation UIWebView (Additional)

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

Try this out and this will hide all the submenu required.

prevent UIWebView inputs from displaying UIKeyboard without disabling user interaction

Then try this:

...
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(removeKeyBoard:) name:UIKeyboardDidShowNotification object:nil];
...

- (void)removeKeyBoard:(NSNotification *)notify {
// web is your UIWebView
[web stringByEvaluatingJavaScriptFromString:@"document.activeElement.blur()"];
}

remember to remove the notification and can filter it if only for your WebView object.



Related Topics



Leave a reply



Submit