繁体   English   中英

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

[英]How to inject/evaluate JS in multiple pages of an iOS webview?

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

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

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

想在www.example.comwww.example.com/about上评估 JS。

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

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

如果你想在加载一个 url 后加载 JS,你可以实现webView(_, didFinish: WKNavigation) WKNavigation 提供 api 来检查请求 / url。
要在导航完成之前加载一些 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添加脚本。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM