phonegap设置资产文件的根目录

phonegap设置资产文件的根目录

本文介绍了phonegap设置资产文件的根目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我已经看过一些问题了,但是我找不到他们是老的,没有任何解决方案。因此我在我的资产文件夹中有以下树:

   -  ressources 
- img
- logo.png
- css
- style.css
- process1
- page1.html
- index.html

我的index.html当我包含img / logo.png或css / style.css一切正常。



但是有相同的结果在page1.html我必须使用../img/logo.png,这很讨厌,因为我有很多页。



我发现了两个丑陋的解决方案:




  • 复制每个子文件夹中的ressources文件夹

  • 创建一个脚本,每个os的根目录的URL(file:/// android_asset / www / for android)


解决方案

也许一个解决方案是使用,允许您将默认基准设置为所有你的亲戚链接。
所以对于android它将是:

 < base href =file:/// android_asset / www / target =_ blank> 

您所有的链接将是:

 < img src =img / logo.png> 


I have seen few questions but I can't find they were old and without any solutions.

So I'n my asset folder I have the following tree:

 - ressources
  - img
     - logo.png
  - css
     - style.css
 - process1
  - page1.html
 - index.html

My "index.html" when I include img/logo.png or css/style.css everything works fine.

But to have the same result in "page1.html" I must use ../img/logo.png and it's quite annoying since I have a lot of pages.

I have found two ugly solutions:

  • Copy the "ressources" folder in each subfolder
  • Create a script that will change all the url to the root directory for each os (file:///android_asset/www/ for android)

解决方案

Maybe a solution is to use the base tag witch allow you to set a default base to all yours relatives links.So for android it will be:

<base href="file:///android_asset/www/" target="_blank">

And all yours link will be:

<img src="img/logo.png">

这篇关于phonegap设置资产文件的根目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 13:50