如何在IOS 14中快速隐藏WKWebView中的页眉和页脚我正在使用以下代码在Webview中加载网站。
webview.load(URLRequest.init(url: URL.init(string: "myURLHere)!))
您需要在加载网站时使用委托功能,例如
self.webview.uiDelegate = self
webview.load(URLRequest.init(url: URL.init(string: 'url here')!))
然后在委托方法中使用以下代码。
public func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
webview.evaluateJavaScript("document.getElementById(\"header_id\").style.display='none';document.getElementById(\"footer_id\").style.display='none';", completionHandler: { (res, error) -> Void in
//Here you can check for results if needed (res) or whether the execution was successful (error)
})
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句