wkwebview 禁止手势长按气泡

2021-01-29  本文已影响0人  泪无痕521

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)
}
}

上一篇下一篇

猜你喜欢

热点阅读