Android的web视图HTML加载JavaScript问题视图、加载、问题、web

2023-09-06 04:36:14 作者:奋斗之路加满油

我一直在解决这个问题超过48小时,现在,我已经无法在网络上的任何地方找到答案。这里的设置:

I've been battling this problem for over 48 hours now and I have been unable to find an answer anywhere on the net. Here's the setup:

我的Andr​​oid应用程序第一次运行期间下载内容(内容超过20MB),文件将在/ mnt / SD卡/ {我的包} /文件夹解压到用户的SD卡。内容包括HTML文件,CSS文件,JS文件和图像。以下是对写入SD卡(其中/ =到/ mnt / SD卡/ {我的包} /文件夹/)的完整​​结构:

My Android application is downloading content during first run (content is over 20MB) and the files are unzipped onto the user's SD card at /mnt/sdcard/{my package}/folder. The content includes HTML files, CSS files, JS files and images. Here's the full structure of what is written to the SD card (where / = /mnt/sdcard/{my package}/folder/):

/内容/

a.html
b.html
images/
  image1.jpg

/ CSS /

/css/

c.css
d.css

/ JS /

/js/

e.js
f.js

下面是我的code加载从SD卡中的HTML文件:

Here is my code that loads the html file from the SD card:

    webView = (WebView) findViewById(R.id.pageBrowser);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.addJavascriptInterface(new LinkHandlerInterface(), "Android");
    webView.setWebViewClient(new PageWebViewClient());

    // contentLocation + url is equal to the full path to the html file
    webView.loadUrl("file://" + contentLocation + url);

这code成功加载HTML页面。没有问题呢。每个页面有以下head标签:

This code successfully loads the HTML page. No problems yet. Each page has the following head tag:

    <link rel="stylesheet" type="text/css" href="../css/screen.css" media="all" />
    <link rel="stylesheet" type="text/css" href="../css/inPractice.css" media="all" />
    <link rel="stylesheet" type="text/css" href="../css/inPracticeScheme.css" media="all" />
    <link rel="stylesheet" type="text/css" href="../css/mobile/iPad.css" media="all" />
    <script type="text/javascript" src="../js/jquery-1.3.2.min.js"></script>
    <script type="text/javascript" src="../js/inPractice-utilities.js"></script>
    <script type="text/javascript" src="../js/inPractice.js"></script>
    <script type="text/javascript" src="../js/mobile/inpractice.ipad.js"></script>

下面是问题的所在。我的WebView呈现HTML就好了。它甚至载荷和施加的CSS完美。但是,它拒绝加载和执行JavaScript。如果你从上面还记得,JS的文件夹,在事实上,人们LEVE从HTML文件,因此它指向正确的位置。

Here is where the problem is. My WebView renders the HTML just fine. It even loads and applies the CSS perfectly. However, it refuses to load and execute the Javascript. If you remember from above, the js folder is, in fact, one leve up from the html file, so it's pointing to the correct place.

这里是我所知道的清单:

Here's a list of what I know:

我正在使用的CSS被应用罚款,所以我知道这个问题是不是与文件位置。

The CSS I'm using is being applied fine, so I know the issue is not with the file location.

我用同样的code之前,但是从我的应用程序的资源文件夹(文件:/// android_assets / ...)中加载文件,它完美地工作。由于内容是如此之大,我不能用我的应用程序,因此移动到SD卡捆绑的。

I used this same code before, but was loading the files from my application's assets folder (file:///android_assets/...) and it worked perfectly. Since the content is so large, I can't bundle it with my application, hence the move to the SD card.

如果我改变了所有的JavaScript方法列举的脚本标签中这样的HTML文件,它工作正常。我没有在HTML控件,所以我不能永久性地应用此更改。这告诉我,web视图没有问题执行JavaScript的。

If I change the HTML files in such a way that all the Javascript methods are listed inside a script tag, it works fine. I don't have control over the HTML, so I can't apply this change permanently. This tells me that the WebView has no problem executing the Javascript.

图像加载的罚款。

我新鲜的想法了。没有人有任何线索,为什么我的WebView无法加载我的JavaScript文件?有没有人见过这个?

I'm fresh out of ideas now. Does anyone have any clue why my WebView cannot load my Javascript files? Has anyone seen this before?

编辑:这里是JS文件我想用都可以在这里看到:

Here are the JS files I'm trying to use can be viewed here:

http://www.automatastudios.com/clients/cco/ inpractice / CSS / inPractice.css http://www.automatastudios.com/clients/cco/inpractice/css/inPracticeScheme.css http://www.automatastudios.com/clients/cco/inpractice/css /screen.css http://www.automatastudios.com/clients/cco/inpractice/css/mobile/iPad.css

http://www.automatastudios.com/clients/cco/inpractice/css/inPractice.css http://www.automatastudios.com/clients/cco/inpractice/css/inPracticeScheme.css http://www.automatastudios.com/clients/cco/inpractice/css/screen.css http://www.automatastudios.com/clients/cco/inpractice/css/mobile/iPad.css

注:这些CSS文件不是由我撰写

推荐答案

从来没有能够找到一个解决的办法。

Was never able to find a solution to this.

我最终只是编辑HTML文件,从而改变了JavaScript源文件的内联JavaScript。这工作(如我所料的那样)。

I ended up just editing the HTML files, such that changed the Javascript source files to inline Javascript. That worked (as I expected it would).