// 禁止选择CSS
NSString *css = @"body{-webkit-user-select:none;-webkit-user-drag:none;}";
// CSS选中样式取消
NSMutableString *javascript = [NSMutableString string];
[javascript appendString:@"var style = document.createElement('style');"];
[javascript appendString:@"style.type = 'text/css';"];
[javascript appendFormat:@"var cssContent = document.createTextNode('%@');", css];
[javascript appendString:@"style.appendChild(cssContent);"];
[javascript appendString:@"document.body.appendChild(style);"];
// javascript注入
WKUserScript *noneSelectScript = [[WKUserScript alloc] initWithSource:javascript injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES];
WKUserContentController *userContentController = [[WKUserContentController alloc] init];
[userContentController addUserScript:noneSelectScript];
WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];
configuration.userContentController = userContentController;
CGRect frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight - 44.f -20.f);
WKWebView *webView = [[WKWebView alloc] initWithFrame:frame configuration:configuration];
NSURLRequest* request = [NSURLRequest requestWithURL:_brandInfoURL];
[webView loadRequest:request];
_webView = webView;
[self.view addSubview:webView];
禁止长按WKWebView出现菜单
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- what the ..... 这不是我们要的效果~ 最近公司要命的催进度,大家决定后面采用web,其实我内心...
- H5web页中由于项目需求,需要实现一个长按弹出自定义菜单供用户选择操作的功能,此功能可用jQuery的 touc...