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)
}
}
网友评论