美文网首页
禁用wkwebview长按

禁用wkwebview长按

作者: 起名真的好难 | 来源:发表于2018-06-04 17:23 被阅读0次
  • (void)noLongTouch
    {
    //禁止长按弹出 UIMenuController 相关
    //禁止选择 css 配置相关
    NSStringcss = @"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.myWebView.configuration.userContentController addUserScript:noneSelectScript];

}

相关文章

网友评论

      本文标题:禁用wkwebview长按

      本文链接:https://www.haomeiwen.com/subject/sxpysftx.html