Home » Android » Chrome on android – not loading local website javascript and css

Chrome on android – not loading local website javascript and css

Posted by: admin June 15, 2020 Leave a comment

Questions:

I have strange problem on Chrome for Android with local website.

It works perfect on Firefox for Andorid, but not for Chrome.

On my site here: https://passcombo.com there is download link with a zip file.

What I do is:

  1. download file to local file system (not SSD! – external storage makes
    another problem!)
  2. I unzip the package and go to the site in local storage using File Commander
  3. I open the html file with Chrome – only HTML loads, no CSS, no JS, no images, no fonts.

Looks like there is path problem with relative paths?

But firefox works!

Working alternative is Firefox, but there you need to write correct strange path: “file:///storage/emulated/0/…./…html”
But…
Currently Chrome is mostly used on Andorid so it’s bad local sites not working :/

How to&Answers:

It doesn’t work opening with file explorer, you have to write the path in the address bar file:///sdcard/Download... or wherever.
JS works with Chrome on local html file in my Galaxy S6.

Answer:

The only solution I found is to:

  1. use firefox
  2. copy folder with my html/css/js to local storage
    (somewhere)
  3. open the site in firefox with path like: file:///storage/emulated/0/myfolder/index.html

where ‘file:///storage/emulated/0/’ is the main path to local storage, and if you copied your folder somehwre deeper then you need to change the ‘myfolder’ to /somefolder1/somesubfolder/…/ sth

Shame it’s the only way to create a web browser app for adroid.

Answer:

In my Android OS version 7, to open a local html file with css and javascript in Google Chrome browser (ver. 64.0.3282.123) I have to open it through an address bar typing as file://localhost/sdcard/, then navigating to the file location. In spite of mention sdcard in the address, it opens an internal storage (and my device has actual removable sdcard as well).

Answer:

It is possible using a HTTP server app on your phone.

For example the SimpleHttpServer.

Set the “Document Root” in the settings of that app to the folder in which your html files reside. Start the server and you will see a local link.
Click on that link and choose the html file you want to show.

If you declared your assets relatively those assets will loaded, too.