HTML代码:
JavaScript代码: function downloadPDF() { window.open('path/to/pdf/file.pdf'); }
JavaScript代码: function downloadPDF() { var file = 'path/to/pdf/file.pdf'; var a = document.createElement('a'); a.href = file; a.download = file.substr(file.lastIndexOf('/') + 1); document.body.appendChild(a); a.click(); document.body.removeChild(a); }
PHP代码: $file = 'path/to/pdf/file.pdf'; header('Content-Type: application/pdf'); header('Content-Disposition: attachment; filename="' . basename($file) . '"'); readfile($file);
注意:此方法需要将页面转发到PHP脚本。
上一篇:按钮按下事件带参数没有触发
下一篇:按钮按下时未显示警告对话框