How to download and import a CSS / JS file from a phone in a telephone conversation?

I am using javascript code to download a CSS file to my phone.

The code works and it saves the CSS file along this path:

file:///data/user/0/com.my.app/files/file.css 

Now I want to download it locally with html code (on my server) as follows:

 <link rel="stylesheet" href="file:///data/user/0/com.my.app/files/file.css"> 

but that will not work.

I also tried putting the CSS file directly in the package (.apk and .ipa) in the css folder in the www folder, but this code does not work either:

 <link rel="stylesheet" href="file:///android_asset/www/css/file.css"> 

Is there a way to download a CSS / JS file locally from a phone?

EDIT:

My phonegap application has an index.html file in the www directory, which simply redirects to my server (i.e. http://www.myserver.com ). I want to import a CSS or JS file on my server ( http://www.example.com ) directly from the phone.

Maybe I can use an iframe (in index.html) and load all the code on my server there instead of redirecting?

+6
source share
2 answers

In the second attempt, you placed the file in the css subfolder of the www root folder. This is the right way to do this, but then you need to reference it using the relative path as follows:

 <link rel="stylesheet" type="text/css" href="css/file.css" /> 

Edit

First of all, if your application is redirected to a server, Apple and possibly other stores will reject your application. According to Apple’s rules , your application must be functional, not just a repackaged site.

Having said that, since you are being redirected to the server, your CSS (and JS) is best left on the server and not imported locally. Just make sure your web page is working correctly in the browser and is connected to the CSS file on the server in a standard way, and will work correctly when your application is redirected to it.

Of course, you need a whitelist of your website, but I assume that you have already done this.

+2
source

I needed to do something similar when reading a file locally to include some content in the page.

You should be able to use this method and bind CSS to the STYLE tag on the page and use LINK. You may need to adjust the path so that everything is correct.

 var filePath = "/android_asset/www/css/file.css"; $.get(filePath, function (data) { $("#css-container").append(filePath); }); <style id="css-container"></style> 
0
source

All Articles