gpt4 book ai didi

ios - 链接到本地​​文件(cdvfile ://) on iOS PhoneGap 3. 3

转载 作者:行者123 更新时间:2023-12-03 07:54:35 24 4
gpt4 key购买 nike

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

编辑 - 请注意,这在 Phonegap 3.4 之前有效,但在 3.5 上无效(当我尝试更改位置时似乎没有任何反应)。如果不是 toURL我用 toNativeURL ,那么它也适用于 3.5。 使用toNativeURL还修复了 iOS 上的当前问题

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

我的链接是相对的(例如 <link href="css/reseter.css" rel="stylesheet"> )。指向其他页面或脚本的链接有效。

这是我打开的简化主页:

<!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>

样式.css

.red { color: red; }

主要.js

alert("HELLO is correctly displayed");

我正确地得到了 alert (它的标题是 cdvfile://localhost/ )我也可以正确地转到 page2.html .唯一的问题是样式。

如果我在 Safari 中打开指向我的电脑的页面,样式会正确显示。

我尝试了一些方法,但无济于事:

  • 添加<base href="cdvfile://localhost/persistent/MyApp/"><head>
  • 更新我所有的 href 和 src 以获得完整的 cdv 文件路径(例如使用 <link href="cdvfile://localhost/persistent/MyApp/css/reseter.css" rel="stylesheet"> )

最佳答案

我终于通过使用 fileSystem.root.fullPath 让它在 PhoneGap 2.9 中工作。在 PhoneGap 3.3 上,它只返回 /。这是 PhoneGap 3.3 上的一个错误吗?当使用 cdvfile 时,除了 CSS 文件之外,一切似乎都有效吗?

我决定暂时使用相对路径我在 PhoneGap 3.3 上的 iOS 应用程序:../../Documents/MyApp/index.html。我不知道使用它是否安全。

编辑Phonegap 3.5(我没有在 3.3 中测试过),使用 work window.location = workingDirectory.toNativeURL() + "/index. html";(即 使用 toNativeURL 而不是 toURL)有效。

关于ios - 链接到本地​​文件(cdvfile ://) on iOS PhoneGap 3. 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22801511/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com