如何将 JavaScript 函数传递给 WebView?

huangapple go评论89阅读模式
英文:

How can I pass javascript function to webview?

问题

我有一个独特的情况。我需要将一个 JavaScript 方法传递给 WebView,以便在 WebView 中启动的 Web 应用能够调用该方法来通知加载状态。加载状态可以是错误、正在加载、已完成等。默认的加载状态并不能给我们一个准确的概念,因此我们的旋转加载图标会消失,但 Web 应用可能尚未加载完成。所以我们希望 Web 应用在实际加载完成时能让 Android 知道。我该如何实现这一点?

英文:

I have a unique situation. I need to pass a javascript method to webview so that the web app I am launching in the webview is able to call that method to notify loading status. The loading status will be error, loading, done etc. The default loading status was not giving us an accurate idea so our spinner would disappear but the web app would not have completed loading. So we want the webapp to let Android know when its actually done loading. How can I achieve this?

答案1

得分: 1

你描述的方法基本上是 WebView 脚本注入。有时知道某事的名称可以产生很大的差异。有许多教程可供参考,我将在这里提供一些链接:

将JS注入到Android的WebView

在Android中使用WebView将JavaScript文件注入到我的网站

英文:

The method you are describing is basically webview script injection. Sometimes knowing the name of something makes all the difference. There are many tutorials out there so I'll just link some here:

Inject JS into Android’s WebView

Inject javascript file to my site with webview in android

huangapple
  • 本文由 发表于 2020年8月26日 13:54:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/63591282.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定