Mut*_*awe 3 javascript css iphone uiwebview ios4
几乎,我已经尝试过所有东西来禁用复制/粘贴,UIWebView但没有任何用处.
我正在UIWebView从字符串(字符串数组)加载我,如下所示:
[webView loadHTMLString:
[NSString stringWithFormat:@"%@<p class=\"paragraph\" style=\"float: right\" >%@</p>",css,[[array objectAtIndex:0] valueForKey:@"content"]] baseURL:nil ];
Run Code Online (Sandbox Code Playgroud)
我试过这个:
-(void)webViewDidFinishLoad:(UIWebView *)webView1{
[webView1 stringByEvaluatingJavaScriptFromString:@"document.body.style.webkitUserSelect='none';"];
}
Run Code Online (Sandbox Code Playgroud)
还有这个:
NSString *css =
@"<head><style><body> *{-webkit-touch-callout: none; -webkit-user-select: none;}</style> </head> </body> ";
Run Code Online (Sandbox Code Playgroud)
但是没有任何关系,特别是对于iOS 4.2
似乎更复杂的是......看看SO上的这个帖子,详细说明你要做的所有事情......
总结:你需要:
修改你的CSS(就像你一样):
<style type="text/css">
* {
-webkit-touch-callout: none;
-webkit-user-select: none; /* Disable selection/Copy of UIWebView */
}
</style>
Run Code Online (Sandbox Code Playgroud)
添加一些JavaScript:
NSString * jsCallBack = @"window.getSelection().removeAllRanges();";
[webView stringByEvaluatingJavaScriptFromString:jsCallBack];
Run Code Online (Sandbox Code Playgroud)
禁用复制/粘贴菜单:
- (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:))
{
return _copyCutAndPasteEnabled;
}
}
return superCanPerform;
}
Run Code Online (Sandbox Code Playgroud)
canPerformAction应该在你的UIWebView中定义; 你有两个选择:
为UIWebView定义一个类别(如果可以从所有UIWebView中删除此行为);
从中派生自己的Web视图类UIWebView并在其中覆盖该方法.
小智 7
-webkit-user-select: none; /* Disable selection/Copy of UIWebView */
Run Code Online (Sandbox Code Playgroud)
还将禁用Mobile Safari上的表单.