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
Programmatically Retrieve Memory Usage on Iphone
Nsfilemanager.Defaultmanager().Fileexistsatpath Returns False Instead of True
How to Check If a String Contains Another String in Objective-C
Periodic iOS Background Location Updates
Swift - Get Device'S Wifi Ip Address
How to Symbolicate Crash Log Xcode
Uiimage(Contentsoffile:) Returning Nil Despite File Existing in Caches Directory
Xcode 6 Bug: Unknown Class in Interface Builder File
How to Change the Push and Pop Animations in a Navigation Based App
How to Send Mail from an Iphone Application
Understanding Ibeacon Distancing
Can You Attach a Uigesturerecognizer to Multiple Views
Generate .Pem File Used to Set Up Apple Push Notifications
How to Pass Textfield Value to View Controller Through Button Click in Swift Ui