我试图在我的 XCode 项目中打开存储在 www/Documents 文件夹中的本地 PDF。我放在 .js 文件中的代码是:
Cordova.exec("ChildBrowserCommand.showWebPage", "file:///www/Documents"+pdf );
其中 pdf 是文件的名称,每个文件都会更改。它在模拟器上运行良好,但在设备上不起作用。我怎样才能解决这个问题?
谢谢!
我试图在我的 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 );
}
}