开发者

Android: Injecting Javascript into a Webview outside the onPageFinished Event

开发者 https://www.devze.com 2023-02-12 22:16 出处:网络
Hey experts, actuall开发者_C百科y it\'s a pretty simple question...just don\'t know about the answer.

Hey experts, actuall开发者_C百科y it's a pretty simple question...just don't know about the answer.

I have an Android app, running a WebView that loads a certain page, also part of the app.

At a given moment, i want to call a javascript function inside the WebView page, but i wanna do this outside the onPageFinished event.

Is that possible? Any ideas?

Thanks in advance.


Is that possible?

Sure. Use loadUrl("javascript:...");, where the ... is whatever Javascript you wish to run in the context of the currently-loaded Web page. It's basically the same trick that bookmarklets use.

Here is a sample project demonstrating this, by pushing a GPS location over to Javascript.

0

精彩评论

暂无评论...
验证码 换一张
取 消