evaluatejavascript

How to load CSS file by using URL in WKWebView

▼魔方 西西 提交于 2020-06-17 12:56:23
问题 I want to inject CSS by using URL link , Working Working below code, If I store CSS file in Bundle path of project, lazy var webView: WKWebView = { guard let path = Bundle.main.path(forResource: "style", ofType: "css") else { return WKWebView() } let cssString = try! String(contentsOfFile: path).components(separatedBy: .newlines).joined() let source = """ var style = document.createElement('style'); style.innerHTML = '\(cssString)'; document.head.appendChild(style); """ let preferences =

How to load CSS file by using URL in WKWebView

依然范特西╮ 提交于 2020-06-17 12:55:25
问题 I want to inject CSS by using URL link , Working Working below code, If I store CSS file in Bundle path of project, lazy var webView: WKWebView = { guard let path = Bundle.main.path(forResource: "style", ofType: "css") else { return WKWebView() } let cssString = try! String(contentsOfFile: path).components(separatedBy: .newlines).joined() let source = """ var style = document.createElement('style'); style.innerHTML = '\(cssString)'; document.head.appendChild(style); """ let preferences =