Android webview脚本标记未加载源文件

时间:2022-12-01 09:10:58

I'm trying to load a javascript file from a script tag in Webview, but it won't load it!

我正在尝试从Webview中的脚本标记加载javascript文件,但它不会加载它!

here's the source for the HTML Script tag:

这是HTML Script标记的来源:

<script type="text/javascript" src="file:///android_asset/game/tetris.js"></script>

And the java file:

和java文件:

WebView webview;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    webview = (WebView) findViewById(R.id.webview);
    webview.getSettings().setJavaScriptEnabled(true);
    webview.loadUrl("file:///android_asset/game/tetris.html");
}

I've tried with and without the "file:///android_asset/game/" and it still won't load!

我尝试过使用和不使用“file:/// android_asset / game /”,它仍然无法加载!

Any ideas? Thanks!

有任何想法吗?谢谢!

1 个解决方案

#1


0  

I do the same in my applications with relative paths, and it works fine for me.

我在相对路径的应用程序中也这样做,它对我来说很好。

In this case I'd simply use src="tetris.js" in the HTML

在这种情况下,我只是在HTML中使用src =“tetris.js”

#1


0  

I do the same in my applications with relative paths, and it works fine for me.

我在相对路径的应用程序中也这样做,它对我来说很好。

In this case I'd simply use src="tetris.js" in the HTML

在这种情况下,我只是在HTML中使用src =“tetris.js”