本文介绍了Phonegap:设置基本href,但仍然包括本地JS / CSS /图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的phonegap index.html文件中进行远程ajax调用,响应是一个html片段,包括对远程服务器上的javascript,css和图像文件的相对引用。为了使相对引用正常工作,我在我的index.html文件中包含一个< base href =http://myserver.com/> 标记。

I am making remote ajax calls in my phonegap index.html file and the response is an html snippet including relative references to javascript, css and image files on the remote server. In order for the relative references to function properly I include a <base href="http://myserver.com" /> tag in my index.html file.

这样可以正常工作。

但是,我想包括本地的CSS / JS / Image文件存储在我的PhoneGap应用程序的www目录。当我将基本href设置为时,我无法再使用相对网址(例如< ; script src =phonegap.0.9.5.js>< / script> )。

However, I would like to also include local CSS/JS/Image files stored in the www directory of my Phonegap Application. As I set the base href to http://myserver.com I can no longer include them using relative URLs (e.g. <script src="phonegap.0.9.5.js"></script>).

我的问题是:我参考这些文件?

My question is: How can I reference these files?

我希望这样的东西可以工作(因为我仍然发布这个问题,它不是那么简单):
< script src =file:///www/phonegap.0.9.5.js>< / script>

I am hoping that something like this will work (as I am still posting this question, it is not quite that simple):<script src="file:///www/phonegap.0.9.5.js"></script>

提前感谢!

推荐答案

我参考的本地图片

./assets/img/img.png

然后当我得到的东西在服务器上我删除起点。所以当我测试我的应用程序,我使用一个asset_path变量,或者有点或不(在你的情况下,你可以把完整的URL)。

and then when I am getting something on the server I remove the starting dot. So when I am testing my application, I use an asset_path variable that either has the dot or not (in your case you could put the full URL).

这篇关于Phonegap:设置基本href,但仍然包括本地JS / CSS /图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 16:02