问题
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