WKWebViewConfiguration 的一些技能配置

// 禁用长按界面弹出列表系统菜单
    private func getConfiguration()->WKWebViewConfiguration{
        // 禁止选择CSS
        let css = "body{-webkit-user-select:text;-webkit-user-drag:none;-webkit-tap-highlight-color: rgba(0, 0, 0, 0);}"
        //let css = ""
        let javascript = NSMutableString()
        javascript.append("var style = document.createElement('style');")
        javascript.append("style.type = 'text/css';")
        javascript.appendFormat("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(source: javascript as String, injectionTime: WKUserScriptInjectionTime.atDocumentEnd, forMainFrameOnly: true)
        let userContentController = WKUserContentController()
        userContentController.addUserScript(noneSelectScript)
        let configuration = WKWebViewConfiguration()
        configuration.userContentController = userContentController
        
        //prints(userContentArr)
        
        for value in userContentArr! {
            //prints(value)
            configuration.userContentController.add(LeakAvoider.init(delegate: self), name: value)
        }
        
        
        let preference = WKPreferences.init()
        preference.javaScriptCanOpenWindowsAutomatically = true
        configuration.preferences = preference
        
        return configuration
    }

你可能感兴趣的:(WKWebViewConfiguration 的一些技能配置)