如何在iOS网页视图的多个页面中注入/评估JS?



似乎android的WebViewClient有这样的方法:onProgressChanged((

有什么关于ios的wkwebview吗?(或任何其他 iOS 网页视图(

Webview的onNavigationStateChange在这里似乎没有帮助。

想在www.example.com上评估JS,然后在www.example.com/about上评估JS。

你说onNavigationStateChange到底是什么意思?这听起来并不熟悉。

您应该实现 WKNavigationDelegate。[https://developer.apple.com/documentation/webkit/wknavigationdelegate]。

如果要在加载 url 后加载 JS,可以实现webView(_, didFinish: WKNavigation)。WKNavigation提供了用于检查请求/URL的API。
要在导航完成之前加载一些 JS,您可以尝试使用webView(WKWebView, decidePolicyFor: WKNavigationAction)[https://developer.apple.com/documentation/webkit/wknavigationdelegate/1455641-webview]
webView(WKWebView, decidePolicyFor: WKNavigationResponse)[https://developer.apple.com/documentation/webkit/wknavigationdelegate/1455643-webview]。

参见 WKUserScript,它是专门为此而设计的。创建 WKWebView 时,您将添加一个 WKUserContentController,该控制器可以使用addUserScript添加脚本。

最新更新