// 禁止选择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];
网友评论