gpt4 book ai didi

javascript - android webview 包含 javascript

转载 作者:行者123 更新时间:2023-11-30 04:45:40 25 4
gpt4 key购买 nike

这可能是一个愚蠢的问题,但我不知道如何将我的 javascript 的 src URL 包含到 Webview 中?

我在代码中构建了一个巨大的 html 标签,传入变量,然后使用 float 图打印它们。 javascript 文件位于我的 Assets 文件夹中,因此在静态 html 页面中,我将它们简单地称为 file:///android_asset/jquery.flot.js。

但是当它全部由代码构建时,我该怎么做呢?这似乎行不通

"<script language=\"javascript\" type=\"text/javascript\" src=\"file:///android_asset/jquery.flot.js\"></script>" +

问候

最佳答案

首先确保您的引用是正确的,其次...研究您是否可以包含本地 Javascript,因为我不确定。

但您为什么不尝试在 <script> 中生成 Javascript 代码(从文件中读取)?标签?也许这可能是一个解决方案。

已编辑:

你看过这个吗?它在 WebView 的 public void loadDataWithBaseURL (String baseUrl, String data, String mimeType, String encoding, String historyUrl)method description :

Note for post 1.0. Due to the change in the WebKit, the access to asset files through "file:///android_asset/" for the sub resources is more restricted. If you provide null or empty string as baseUrl, you won't be able to access asset files. If the baseUrl is anything other than http(s)/ftp(s)/about/javascript as scheme, you can access asset files for sub resources.

关于javascript - android webview 包含 javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5027015/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com