Chrome on android - not loading local website javascript and css
Solution 1
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
.
Solution 2
The only solution I found is to:
- [update 2021] use Opera (Firefox did work before recent update!)
- copy folder with my html/css/js to local storage (somewhere)
- open the sitewith path like: [current Opera] file:///storage/0000-0000/MyFolder/index.html [old in firefox ] file:///storage/emulated/0/myfolder/index.html
where 'file:///storage/0000-0000/' OR '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.
Solution 3
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.
Solution 4
Seems like the only directory Chrome reads local files from is file:///sdcard/Android/data/com.android.chrome/files/Download/
Solution 5
The only solution worked for me in Android is the HTTP Web Server (I used Simple HTTP Server).
Installing different browsers didn't help:
(Apr-2021) I tried installing various Browsers (Chrome, FireFox, even Opera etc.) in Android but none worked. In all cases, when I navigated to the folder containing HTML/JS files using local file:///
URLs ('file:///sdcard/
' or 'file:///storage/emulated/0/
') browsers only displayed the folders but no files.
When I used the absolute path to the HTML file the browsers used content:///
protocol to
render static HTML content, i.e. it did NOT allow execution of JavaScript code.
kkonrad
Updated on July 05, 2022Comments
-
kkonrad almost 2 years
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:
- download file to local file system (not SSD! - external storage makes another problem!)
- I unzip the package and go to the site in local storage using File Commander
- 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 :/
-
kkonrad over 6 yearsyes, but this workaround and a bit shame you need to use it; shuold work directly in the browser, like on a desktopn computer :)
-
David Miguel almost 6 yearsI was getting access denied in Firefox, but it was because Storage permission was not granted. Then it worked fine. Thanks.
-
Eddie Kumar about 3 yearsDoesn't work now in year 2021. file:///sdcard/ does not show .html files (it shows local folders but not HTML/JS files.)
-
Eddie Kumar about 3 yearsOpera in Android is not showing/opening the .html files, the 'file:///sdcard/' or 'file:///storage/emulated/0/' does show the folders but no files. Any other ideas/workarounds? TIA.
-
kkonrad about 3 yearsFor me current version of Opera 62.3 opens index.html - just need to type correct path file:///storage/0000-0000/MyFolder/index.html , an be sure to grand access .
-
kkonrad about 3 yearsUpdated the file path - bit different in Opera. Maybe that is the issue? For me it works with Opera 62.3
-
foodiepanda almost 3 years@eddie.... It shows all files.. just click on HTML file and you are good'
-
user over 2 yearsThis does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review