是否可以在webview中注入javascript [英] Is it possible to inject javascript in webview

查看:80
本文介绍了是否可以在webview中注入javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将javascript注入第三方网页-我正在尝试预填充一些INPUT字段.

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.

查看WebView的ios代码-我看到构造函数实际上注入了它自己的JS代码.只是想知道我也可以做同样的事情.

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.

我尝试在loadFinishedEvent期间注入-但我认为为时已晚.

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

也许我需要对Webview进行子类化-我该怎么做,还能够在xml页面定义中指定新类.

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.

推荐答案

我认为您无法在加载网页后注入JavaScript.创建WKWebView时必须这样做.

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

这是另一个SO线程,它为您提供了一个示例,以覆盖WKWebView的创建以注入您自己的JavaScript .目的是禁用收缩缩放.

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.

这篇关于是否可以在webview中注入javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆