繁体   English   中英

如何使用Javascript创建下载文件而不将其保存在服务器中

[英]How to create a download file and not save it in server with javascript

我有关于如何创建按钮的问题,该按钮将为一格下载PDF文件。

我试过像这样的window.print()

$(document).ready(function(){

        $('#printBtn').on('click',function(){
            window.print();
        });

    });

并将其另存为PDF文件。 我不知道其他方式,我也不想先将其保存在服务器上。

您尝试使用elements 属性下载直接下载链接

<a href="/images/myw3schoolsimage.jpg" download>

- - 要么 - -

<button id="print" onclick="print('uname');" >Print</button>
<div id="uname">
<label>Name</label>
<label>Spider</label>
</div>

<button id="print" onclick="printContent('uname');" >Print</button>

    function print(e){var divToPrint=document.getElementById('e');

    var newWin=window.open('','Print-Window');

    newWin.document.open();

    newWin.document.write('<html><body onload="window.print()">'+divToPrint.innerHTML+'</body></html>');

    newWin.document.close();

    setTimeout(function(){
        newWin.close();
    },10);
}

在这里演示

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM