假设我有一个移动网站,它使用根网址路径来包含资产,例如:
<link rel="stylesheet" href="/_assets/css/jquery.mobile.theme.css" />
<link rel="stylesheet" href="/_assets/css/jquery.mobile.structure-1.0.min.css" />
Run Code Online (Sandbox Code Playgroud)
在PhoneGap中,似乎我不能以这种方式链接到文件.在我的index.html文件中,它们必须是相对路径,例如:
<link rel="stylesheet" href="_assets/css/jquery.mobile.theme.css" />
Run Code Online (Sandbox Code Playgroud)
但是位于我的目录结构深处的文件怎么样,比如/sub/dir/index.html.使用相对路径我将不得不使用以下内容:
<link rel="stylesheet" href="../../_assets/css/jquery.mobile.theme.css" />
Run Code Online (Sandbox Code Playgroud)
是否可以以某种绝对的方式引用此文件?我试过以下没有成功:
<link rel="stylesheet" href="/www/_assets/css/jquery.mobile.theme.css" />
<link rel="stylesheet" href="file:///www/_assets/css/jquery.mobile.theme.css" />
<link rel="stylesheet" href="file://www/_assets/css/jquery.mobile.theme.css" />
<link rel="stylesheet" href="local:///www/_assets/css/jquery.mobile.theme.css" />
<link rel="stylesheet" href="local://www/_assets/css/jquery.mobile.theme.css" />
<link rel="stylesheet" href="file:///_assets/css/jquery.mobile.theme.css" />
<link rel="stylesheet" href="file://_assets/css/jquery.mobile.theme.css" />
<link rel="stylesheet" href="local:///_assets/css/jquery.mobile.theme.css" />
<link rel="stylesheet" href="local://_assets/css/jquery.mobile.theme.css" />
Run Code Online (Sandbox Code Playgroud)
甚至可能还有一些尝试.我真的更喜欢不必使用相对网址,所以希望有可能.
在iOS上阅读带有资产的绝对路径URL的PhoneGap后,我真的很困惑, 并且有几个问题:
我试着在这里使用ionic/cordova插件.
所以我把这段代码放在我的页面中:
showDocument() {
var options: DocumentViewerOptions = {
title: 'A book',
documentView: { closeLabel: '' },
navigationView: { closeLabel: '' },
email: { enabled: true },
print: { enabled: true },
openWith: { enabled: true },
bookmarks: { enabled: true },
search: { enabled: false },
autoClose: { onPause: false }
}
this.docViewer.viewDocument('assets/arabic.pdf', 'application/pdf', options);
}
Run Code Online (Sandbox Code Playgroud)
还有一个简单的按钮可以在html页面中启动它:
<ion-content>
<button ion-button round (click)="showDocument()">
Read
</button>
</ion-content>
Run Code Online (Sandbox Code Playgroud)
但我在模拟器中看不到任何内容(因为无法在浏览器上运行它)
离子信息在那里:
更新:
这是我使用我的设备和chrome devtools进行调试时得到的结果:
更新2:
我试图使用绝对路径,但我有空值,我做了这些更改:
import …Run Code Online (Sandbox Code Playgroud) 我有一个混合应用程序,使用Cordova 3.7和jQuery Mobile 1.3.2在iOS 7上完美运行
我在iOS 8上测试它并且它已经坏了.我正在使用绝对路径请求我的应用程序的每个页面(视图),使用file://协议,如:
file:///var/mobile/Applications/<UUID>/MyApp.app/www/views/add-project.html
但我得到错误:
Failed to load resource: The requested URL was not found on this server.
我读到了这个bug,是问题吗?
此外,在iOS 8上,www文件夹的位置与iOS 7略有不同,它解析为:
file:///var/mobile/Containers/Data/Application/<UUID>/MYApp.app/www/views/add-project.html
它是否正确?
我尝试使用toURL()和toInternalURL()方法来获得绝对路径:
cdvfile://localhost/root/var/mobile/Containers/Bundle/Application/<UUID>/MyApp.app/但我总是得到同样的错误.有什么建议吗?
谢谢