Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/185.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
加载Javascript&;webview中的HTML_Javascript_Android_Html_Webview - Fatal编程技术网

加载Javascript&;webview中的HTML

加载Javascript&;webview中的HTML,javascript,android,html,webview,Javascript,Android,Html,Webview,我在让Javascript在Webview中工作时遇到了一些问题。基本上,我所做的是使用Webview客户端,然后在那里加载html文件: super.onCreate(savedInstanceState); setContentView(R.layout.main); mWebView = (WebView) findViewById(R.id.webview); mWebView.setWebViewClient(new HelloWebViewClient());

我在让Javascript在Webview中工作时遇到了一些问题。基本上,我所做的是使用Webview客户端,然后在那里加载html文件:

super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    mWebView = (WebView) findViewById(R.id.webview);
    mWebView.setWebViewClient(new HelloWebViewClient());
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.getSettings().setAllowFileAccess(true);
    mWebView.getSettings().setPluginsEnabled(true);
    mWebView.loadUrl("file:///android_asset/test/test.html");
Webview加载完美,html显示无问题

在html文件中,加载我使用的javascript文件

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

Javascript文件也位于assets文件夹中。html/javascript在我的笔记本电脑的普通浏览器中运行,效果很好,但我就是无法在Android中运行。我尝试过在没有设置WebView客户端的情况下运行它,但也没有成功


任何帮助都将不胜感激

您可以尝试使用javascript文件的完整路径引用。

只是一个建议!将文件夹结构更改为

 .../assets/www
然后尝试将js放入名为“lib”的文件夹中/资产/www/lib

然后尝试这样的代码

<script type="text/javascript" src="lib/test.js"></script>

你为什么建议这些改变?
mWebView.loadUrl("file:///android_asset/www/test.html");