Is it possible to inject javascript in webview

一世执手 提交于 2019-12-13 03:46:08

问题


Is it possible to inject javascript into a third party web-page - i'm trying to pre-fill some INPUT fields.

I've got a feeling the answer will be no - but maybe possible in native code.

Looking at the ios code for WebView - I see that the constructor actually injects it's own JS code. Just wondering how I could also do the same.

I tried to inject during the loadFinishedEvent - but I think it's too late.

Maybe I need to sub-class Webview - how would I do that and also be able to specify the new class in xml page definition.


回答1:


I don't think you could inject JavaScript after a web page is loaded. You will have to do it while creating the WKWebView.

Here is another SO thread that gives you an example to override the creation of WKWebView to inject your own JavaScript. The purpose was to disable pinch zoom.



来源:https://stackoverflow.com/questions/54847766/is-it-possible-to-inject-javascript-in-webview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!