簡體   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