机器人的WebView加载本地的javascript [英] Android webview load local javascript

查看:112
本文介绍了机器人的WebView加载本地的javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图加载存储通过HTML文件,该文件是通过一个web视图加载设备上的JavaScript文件,但似乎永远不会加载。我曾尝试使用直接的网址就像你通常会在HTML和也尝试过:

I am trying to load a javascript file stored on the device via html file which is loaded via a webview but never seems to load. I have tried using direct url's like you normally would in html and have also tried:

<脚本类型=文/ JavaScript的SRC =文件:///android_asset/www/js/jsfile.js/>

JavaScript是在web视图设置过于启用,工作正常,如果我把它的服务器上。

JavaScript is enabled on the webview settings too and works fine if I have it on a server.

感谢,如果有人可以提供帮助。

Thanks if anyone can help.

推荐答案

您好其实我的事,你应该直接调用JS文件,因为你是从它参考资产的文件夹是它的根文件夹浏览器调用它。从Java code调用时preFIX:您应该使用///文件。尝试是这样的:

Hi actually I thing you should call directly the js file because you are calling it from the browser which considers the asset folder being its root folder. You should use the "file:///" prefix when calling from java code. Try something like this:

<script type="text/javascript" src="www/js/jsfile.js"/>

这篇关于机器人的WebView加载本地的javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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