我想在Android中使用phonegap InAppBrowser显示外部PDF,但它不起作用.
这是我的JS代码:
<script>
function openPDF() {
var ref = window.open('http://www.i-drain.net/userfiles/file/einbauanleitung_iboard.pdf', '_blank', 'location=yes');
ref.addEventListener('loadstart', function(event) { alert('start: ' + event.url); });
ref.addEventListener('loadstop', function(event) { alert('stop: ' + event.url); });
ref.addEventListener('loaderror', function(event) { alert('error: ' + event.message); });
ref.addEventListener('exit', function(event) { alert(event.type); });
}
</script>
Run Code Online (Sandbox Code Playgroud)
我想在点击图片后打开pdf,所以我使用这个HTML代码:
<a href="#" onclick="openPDF()" >
<img src="images/button.png">
</a>
Run Code Online (Sandbox Code Playgroud) 我想从网址下载pdf文件.为了查看pdf文件,我使用了以下代码.
File file = new File("/sdcard/example.pdf");
if (file.exists()) {
Uri path = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
try {
startActivity(intent);
}
catch (ActivityNotFoundException e) {
Toast.makeText(OpenPdf.this, "No Application Available to View PDF",
Toast.LENGTH_SHORT).show();
}
}
Run Code Online (Sandbox Code Playgroud)
它正在工作,但我如何从URL(例如http://.../example.pdf)获取pdf文件.我想从这个网址下载 pdf文件.请帮我.提前致谢.
目前我正在下载模块.用户单击下载按钮后,将从服务器下载文件(pdf,zip文件或docx),并将其存储在本地存储中.我可以使用FileTransfer.Download()方法下载文件,但我无法通过传递文件路径打开它.
以下是我的代码:
<!DOCTYPE HTML>
<html>
<head>
<meta name = "viewport" content = "user-scalable=no,width=device-width" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Test Page</title>
<script type="text/javascript" charset="utf-8" src="js/cordova-2.0.0.js"></script>
<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
<style type="text/css">
* {
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}
</style>
<script type="text/javascript" charset="utf-8">
function init() {
document.addEventListener("deviceready", ready, true);
}
function ready() {
console.log("App is ready.");
}
function download() {
// var remoteFile = "https://dl.dropbox.com/u/6731723/a.zip";
var remoteFile = "https://dl.dropbox.com/u/6731723/Beaver.pdf";
var localFileName = remoteFile.substring(remoteFile.lastIndexOf('/') + 1);
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) {
fileSystem.root.getFile(localFileName, { …Run Code Online (Sandbox Code Playgroud)