07-07-2011, 03:44 PM
#1 (permalink )
Registered Member
Join Date: Nov 2010
Posts: 104
disable copying in UIWebView
Hey all,
I am trying to disable the function in the UIWebView that allows the user to doulbe tap the screen swipe down, creating a blue window that says copy. I am using
Code:
body
{
width: 300px;
height: 130px;
font-family: verdana;
font-size: small;
-webkit-touch-callout: none;
-webkit-user-select: none;
-webkit-user-drag: none;
-webkit-user-modify: none;
-webkit-highlight: none;
}
in my css class but it is still happening. Is there anything else I need to put in there
Thanks
Clinton
07-08-2011, 04:50 PM
#2 (permalink )
Nuisance Developer
Join Date: Jul 2009
Location: Italy
Posts: 4,691
mmm...post the entire code.
__________________
07-08-2011, 05:52 PM
#3 (permalink )
Registered Member
Join Date: Nov 2010
Posts: 104
This is all the css code right so far
Code:
body
{
width: 300px;
height: 130px;
font-family: verdana;
font-size: small;
-webkit-touch-callout: none;
-webkit-user-select: none;
-webkit-user-drag: none;
-webkit-user-modify: none;
-webkit-highlight: none;
}
#divContent
{
position:absolute;
left:15px;
top:100px;
width:500;
height:500;
border:thin;
border-color:#000000;
background-color:#FFFFCC;
}
#btnTest
{
position:absolute;
left:330px;
top:55px;
}
07-08-2011, 11:32 PM
#4 (permalink )
Registered Member
Join Date: Dec 2010
Posts: 19
it has to be in html file
<style type="text/css">
body {-webkit-user-select:none}
</style>
it works for sure!!!
try disabling other options (put //) and only leaving this one
__________________
Last edited by Vixy; 07-08-2011 at 11:37 PM .
07-09-2011, 02:23 AM
#5 (permalink )
Nuisance Developer
Join Date: Jul 2009
Location: Italy
Posts: 4,691
when i say "post the entire code" i mean also (and mainly) the objective-c part
__________________
07-11-2011, 02:33 PM
#6 (permalink )
Registered Member
Join Date: Nov 2010
Posts: 104
Hey Vixy the code you provided didn't work. I was still able to double tap the screen and drag down to make a blue copy window appear.
Dany I can't post my entire code but this is all I do with the web view
Code:
[webView loadData:htmlData MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:[NSURL URLWithString:@"/var/mobile/Applications/F0BB0B99-F1B1-4618-A86C-12652EBA0DB6/myApp.app/filesFolder/"]];
Thanks for the help
07-11-2011, 03:53 PM
#7 (permalink )
Senior Member
iPhone Dev SDK Supporter
Join Date: Aug 2008
Location: Memphis, TN, USA
Age: 24
Posts: 3,983
07-11-2011, 05:19 PM
#8 (permalink )
Registered Member
Join Date: Nov 2010
Posts: 104
I already have the first method in place and I tried the other 2. I put the second method in viewDidLoad and webViewDidFinishLoad and it did nothing. I put the third method into my viewcontroller and I got an error. The _copyCutAndPasteEnabled is not declared. So I just declared it as a BOOL but I do not know what to do with that BOOL
07-12-2011, 12:06 PM
#9 (permalink )
Registered Member
Join Date: Dec 2010
Posts: 19
this describes what you want
iLessons iLearned: How to Disable UIWebView Selection
if it doesn't work you are probably changing it somewhere else in html, try finding if there are any other occurances
good luck
it worked for me!
__________________
07-12-2011, 12:40 PM
#10 (permalink )
Registered Member
Join Date: Nov 2010
Posts: 104
I have no other styles except for this in my html
Code:
<style type="text/css">
body {-webkit-user-select:none;
-webkit-touch-callout: none;
-webkit-user-drag: none;
-webkit-user-modify: none;
-webkit-highlight: none;}
</style>
And my css looks like
Code:
body
{
width: 300px;
height: 130px;
font-family: verdana;
font-size: small;
-webkit-touch-callout: none;
-webkit-user-select: none;
-webkit-user-drag: none;
-webkit-user-modify: none;
-webkit-highlight: none;
}
#divContent
{
position:absolute;
left:15px;
top:100px;
width:500;
height:500;
border:thin;
border-color:#000000;
background-color:#FFFFCC;
}
#btnTest
{
position:absolute;
left:330px;
top:55px;
}
All the copy/paste and magnifying glass have been removed with these styles but I am still able to double tap the screen and swipe down making a blue copy box at the top of my screen.
08-05-2011, 05:06 AM
#11 (permalink )
Registered Member
Join Date: Dec 2010
Posts: 79
Does anyone know how to disable copying in UIWebView for 4.3? I've tried every link above, but it doesn't work!
This is my code:
Code:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
// String attributes - show them in the user interface
NSString * jsCallBack = @"window.getSelection().removeAllRanges();";
[tvtext stringByEvaluatingJavaScriptFromString:jsCallBack];
NSString *myHtml = [NSString stringWithFormat:
@"<html><head>"
"<style type=\"text/css\">"
// Disable Open/Copy/Cancel alert with long link selection
"* {"
"-webkit-touch-callout: none;"
// Disable selection/Copy of UIWebView
"-webkit-user-select: none;"
"font-family:Helvetica;"
//"p {font-size:x-small;}"
"body {-webkit-user-select:none;}"
"}"
",</style>"
"</head><body>%@</body></html>", [referringObject valueForKey:@"stext"]];
[tvtext loadHTMLString:myHtml baseURL:nil];
}
10-17-2011, 05:00 AM
#12 (permalink )
Registered Member
Join Date: Oct 2011
Posts: 1
Well, I'm new here, and I also found the answer.Here is the html you load into the UIWebView:
HTML Code:
<head>
<style type="text/css" >
body {
-webkit-touch-callout: none;
-webkit-user-select: none;
-webkit-user-drag: none;
-webkit-user-modify: none;
-webkit-highlight: none;
}
</style>
<div
ontouchstart="touchStart(event);"
> </div>
</head>
<body> TextHere with Link<a href=http://developer.apple.com> apple developer</a>
</body>
and then write the code in your view:
Code:
NSString *html=[NSString stringWithString:@"\
<html>\
<head>\
<style type=\"text/css\">\
body {\
-webkit-touch-callout: none;\
-webkit-user-select: none;\
-webkit-user-drag: none;\
-webkit-user-modify: none;\
-webkit-highlight: none;\
}\
</style>\
<div\
ontouchstart=\"touchStart(event);\"\
></div>\
</head>\
<body>%@</body>\
</html>\
"];
[webView loadHTMLString:html baseURL:nil];
for more, you can click:
Loading
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
» Advertisements
» Online Users: 354
9 members and 345 guests
apatsufas , chemistry , lendo , leostc , Leslie80 , lzwasyc , MarkC , SamorodovAlex , VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,664
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Leslie80