Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 无法使用PhoneGap查看pdf文件_Jquery_Cordova_Pdf - Fatal编程技术网

Jquery 无法使用PhoneGap查看pdf文件

Jquery 无法使用PhoneGap查看pdf文件,jquery,cordova,pdf,Jquery,Cordova,Pdf,我试图查看已下载的pdf,但没有显示它的运气 这是我下载和显示文件的代码。当我试图打开文件时,我只会收到一个警报,说无法查看文件 jQuery // Download edition's pdf file function downloadFile(filename){ var localDir = cordova.file.dataDirectory; // Validate if file exist before download window.resolveLoc

我试图查看已下载的pdf,但没有显示它的运气

这是我下载和显示文件的代码。当我试图打开文件时,我只会收到一个警报,说无法查看文件

jQuery

// Download edition's pdf file
function downloadFile(filename){
    var localDir = cordova.file.dataDirectory;
    // Validate if file exist before download
    window.resolveLocalFileSystemURL(localDir + filename, function(){
        ShowPDF(localDir + filename);
    }, function(){
        window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, 
        function onFileSystemSuccess(fileSystem) {
            fileSystem.root.getFile(
                "index.html", {create: true, exclusive: false}, 
                function gotFileEntry(fileEntry) {
                    //var sPath = fileEntry.fullPath.replace("index.html","");
                    var localDir = cordova.file.dataDirectory;
                    var fileTransfer = new FileTransfer();
                    fileEntry.remove();

                    fileTransfer.download(
                        path + filename,
                        localDir + filename,
                        function(theFile) {
                            ShowPDF(theFile.toURI());
                            console.log("download complete: " + theFile.toURI());
                        },
                        function(error) {
                            console.log("download error source " + error.source);
                            console.log("download error target " + error.target);
                            console.log("upload error code: " + error.code);
                            console.log(error);
                        }
                    );
            }, fail);
    }, fail);
    });
};

// Show downloaded pdf
function ShowPDF(filePath){
    window.open(filePath, '_system', 'location=yes')
};
编辑: 我刚刚意识到,这部分还将使用浏览器下载文件,然后您可以查看下载的文件

window.open(path + filename, '_system', 'location=yes');
在显示本地文件之前,我需要验证文件是否已下载

更新


我照此操作,但仍然无法查看本地文件

您无法在cordova webview中打开PDF。
试试Phonegap插件

我目前正在使用fileOpener插件,但仍然没有成功。请确保您的设备中至少有一个pdf阅读器。是的,我的手机上有阅读器。我认为可能的问题是,存储文件的位置可能没有读取文件的权限。我正在调查这个问题