我尝试打开存储在 XCode 项目的 www/Documents 文件夹中的本地 PDF。我放入 .js 文件的代码是:
Cordova.exec("ChildBrowserCommand.showWebPage", "file:///www/Documents"+pdf );
其中 pdf 是文件名,每个文件都会更改。它在模拟器上运行良好,但在设备上不起作用。我该如何解决这个问题?
谢谢!
最佳答案
我正在使用以下函数在子浏览器中加载文件,它会创建正确的本地 url,以防您要加载内部文件:
function loadChildBrowser(isInternal, URL) {
if(isInternal){
var strPath = window.location.href;
var path = strPath.substr(0,strPath.lastIndexOf('/')) + URL;
cb.showWebPage(encodeURI(path));
}
else{
cb.showWebPage(URL);
}
}
编辑
为你的情况试试这个:
function loadChildBrowser(isInternal, URL) {
if(isInternal){
var strPath = window.location.href;
var path = strPath.substr(0,strPath.lastIndexOf('/')) + URL;
Cordova.exec("ChildBrowserCommand.showWebPage", encodeURI(path) );
}
else{
Cordova.exec("ChildBrowserCommand.showWebPage", URL );
}
}
关于iphone - 使用 iOS 在 cordova 项目中打开本地 pdf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11184554/