此外.如果你们的产品和我们一样,对文档有权限要求,比如,不允许选择,复制,粘贴,等操作,我们可以通过js注入WKWebView的方法让禁止用户交互,代码如下
//禁止长按弹出 UIMenuController 相关//禁止选择 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 appendString:@"document.documentElement.style.webkitUserSelect='none';"];//禁止选择[javascript appendString:@"document.documentElement.style.webkitTouchCallout='none';"];//禁止长按//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;//控件加载[self.webView.configuration.userContentController addUserScript:noneSelectScript];[self.view addSubview:self.webView];[self.webView mas_makeConstraints:^(MASConstraintMaker*make){make.top.left.right.bottom.equalTo(self.view);}];
作者:空空小僧
链接:https://www.jianshu.com/p/91196eba0f27
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
网友评论