美文网首页
wkwebview 禁止手势长按气泡

wkwebview 禁止手势长按气泡

作者: 泪无痕521 | 来源:发表于2021-01-29 18:55 被阅读0次

    public extension WKUserContentController {
    //禁用长按手势气泡
    func tc_addLongPressGestureRecognizerHandle() {
    let css = "body{-webkit-user-select:none;-webkit-user-drag:none;}"
    var javascript = ""
    javascript.append("var style = document.createElement('style');")
    javascript.append("style.type = 'text/css';")
    javascript.append(String.init(format: "var cssContent = document.createTextNode('%@');", css))
    javascript.append("style.appendChild(cssContent);")
    javascript.append("document.body.appendChild(style);")
    javascript.append("document.documentElement.style.webkitUserSelect='none';")//禁止选择
    javascript.append("document.documentElement.style.webkitTouchCallout='none';")//禁止长按
    let noneSelectScript = WKUserScript.init(source: javascript, injectionTime: .atDocumentEnd, forMainFrameOnly: true)
    self.addUserScript(noneSelectScript)
    }
    }

    相关文章

      网友评论

          本文标题:wkwebview 禁止手势长按气泡

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