链接到iOS PhoneGap 3.3上的本地文件(cdvfile://) [英] Link to local files (cdvfile://) on iOS PhoneGap 3.3

查看:247
本文介绍了链接到iOS PhoneGap 3.3上的本地文件(cdvfile://)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要轻松更新我的应用程序,我将www文件夹的内容复制到手机,然后执行 window.location = workingDirectory.toURL()+/index.html\"



EDIT - 注意这个在Phonegap 3.4之前有效,但不在3.5更改位置)。如果不是 toURL 我使用 toNativeURL ,那么它也工作在3.5。 使用 toNativeURL 也可修复iOS上的当前问题



复制所有文件打开索引在iOS和Android上都可以正常工作。 iOS上的问题是,绝对没有样式的页面,如果CSS文件的链接不工作。一切都在Android上正常工作。



我的链接是相对的(例如< link href =css / reseter.css =stylesheet > )。



这是我打开的简化主页:

 <!DOCTYPE html> 
< html>
< head>
< title>< / title>
< link href =style.css =stylesheet>
< script src =main.js>< / script>
< / head>
< body>
< div class =red>我应该是红色的,但我不是!< / div>
< a href =page2.html>这正确地将我转到其他页面。< / a>
< / body>
< / html>

style.css

  .red {color:red; } 

main.js

  alert(HELLO is correctly displayed); 

我正确地得到警告 cdvfile:// localhost / ),我也可以正确地转到 page2.html 。唯一的问题是样式。



如果我在Safari中指向我的计算机打开页面,则会正确显示样式。



我试过几件事,无济于事:




  • 添加< base href =在< head>

  • 中的cdvfile:// localhost / persistent / MyApp /> >更新我的所有href和src以拥有完整的cdvfile路径(例如使用< link href =cdvfile://localhost/persistent/MyApp/css/reseter.css =stylesheet> ;


解决方案

> PhoneGap 2.9 使用 fileSystem.root.fullPath 。在PhoneGap 3.3它只返回 / 。这是一个在PhoneGap 3.3的bug,当使用cdvfile,一切似乎工作除了CSS文件?



我决定暂时使用相对路径到我的应用程序iOS上PhoneGap 3.3: ../../ Documents / MyApp / index.html

Phonegap 3.5 (我不知道如何使用)使用工作 window.location = workingDirectory.toNativeURL()+/index.html; (即使用 toNativeURL 而不是 toURL )。


To easily update my app, I copy the content of the www folder to the phone and then do a window.location = workingDirectory.toURL() + "/index.html".

EDIT - note that this works until Phonegap 3.4, but not on 3.5 (nothing seems to be happening when I try to change the location). If instead of toURL I use toNativeURL, then it works also on 3.5. Using toNativeURL also fixes the current issue on iOS.

Copying all the files and opening the index works fine on both iOS and Android. The problem on iOS though is that there is absolutely no styling to the page, as if the links to the CSS files weren't working. Everything is working fine on Android.

My links are relative (eg <link href="css/reseter.css" rel="stylesheet">). Links to other pages or to scripts do work.

Here is the simplified main page I open:

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <link href="style.css" rel="stylesheet">
    <script src="main.js"></script>
</head>
<body>
    <div class="red">I should be red but I'm not!</div>
    <a href="page2.html">This correctly takes me to the other page.</a>
</body>
</html>

style.css

.red { color: red; }

main.js

alert("HELLO is correctly displayed");

I correctly get the alert (its title is cdvfile://localhost/) and I can also correctly go to page2.html. The only problem is with the styles.

If I open the page in Safari pointing to my computer, the style is correctly displayed.

I tried a few things, to no avail:

  • Add <base href="cdvfile://localhost/persistent/MyApp/"> in the <head>
  • Update all my href and src to have the full cdvfile path (eg use <link href="cdvfile://localhost/persistent/MyApp/css/reseter.css" rel="stylesheet">)

解决方案

I finally got it working in PhoneGap 2.9 by using fileSystem.root.fullPath. On PhoneGap 3.3 it only return /. Is this a bug on PhoneGap 3.3 that when using cdvfile, everything seems to work except the CSS files?

I decided to temporally use a relative path to my app for iOS on PhoneGap 3.3: ../../Documents/MyApp/index.html. I don't know if it's safe to use or not.

EDIT In Phonegap 3.5 (I haven't tested in 3.3), using work window.location = workingDirectory.toNativeURL() + "/index.html"; (ie using toNativeURL instead of toURL) works.

这篇关于链接到iOS PhoneGap 3.3上的本地文件(cdvfile://)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆