如何在Phonegap中使用Javascript在Android Web浏览器中查看PDF文件?

时间:2014-01-02 11:40:10

标签: android cordova pdf-viewer

我必须使用phonegap在android中打开pdf文件。 我在iOS中尝试过,它工作正常,但在Android设备上的代码不一样

以下是适用于iOS的代码

function Application() {
}
Application.prototype.Run = function() {
    if (device.uuid == "e0101010d38bde8e6740011221af335301010333" || device.uuid == "e0908060g38bde8e6740011221af335301010333") {
        alert("Not Supported in Simulator.");
    }
    else {
        var infoDiv = document.getElementById("infoField");
        var path = this.getWorkingFolder().replace('http://', 'file://') + "sample.pdf";
        infoDiv.innerText = path;

        if (device.platform === 'Android') {
            window.open(path, '_system');
        }
        else {
            window.open(path, '_blank');
        }
    }
}

Application.prototype.getWorkingFolder = function() {
    var path = window.location.href.replace('index.html', '');
    return path;
}
function onDeviceReady() {
    alert('OnDevice Ready called');
    //navigator.splashscreen.hide();
    document.getElementById('btnOpenPDF').onclick = function() {
        var app = new Application();
        app.Run();
    }
}
document.addEventListener("deviceready", onDeviceReady, false);

0 个答案:

没有答案