简体   繁体   English

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

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

i have problem about how to create button which will downloading PDF file for one div. 我有关于如何创建按钮的问题,该按钮将为一格下载PDF文件。

i tried window.print() like this : 我试过像这样的window.print()

$(document).ready(function(){

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

    });

and save it as PDF file. 并将其另存为PDF文件。 i don't know other ways than that and i don't want to save it on server first. 我不知道其他方式,我也不想先将其保存在服务器上。

You try direct download link with using a elements attribute download 您尝试使用elements 属性下载直接下载链接

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

---- OR ---- - - 要么 - -

<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);
}

Demo Here 在这里演示

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

相关问题 如何从服务器下载文件并通过对话框保存 - How to download file from server and save it with dialog 如何使用 javascript 在下载 function 中保存带有名称的文件? - how to save file with name in a download function with javascript? 如何下载 json 文件并将其保存为服务器上的 js 文件? - How to download a json file and save it as a js file on server? 如何使用 JavaScript 创建和保存文本文件 - How to create and save a text file with JavaScript 如何通过按Java中的按钮将文件保存到服务器 - How to save a file to the server by pressing a button in Javascript 如何从textarea保存文件并在下载代码中配置路径? JavaScript - How to save file from textarea and configure path in download code? JavaScript 如何使用mvc或javascript下载另存为对话框的文件 - How to download file with save as dialog using mvc or javascript 创建表客户端,然后下载excel文件或在服务器端生成excel文件,保存到服务器,然后使用JQuery从那里下载? - Create table client side, then download excel file OR generate excel file server-side, save to server, and use JQuery to download from there? 使用字节数组创建 PDF 文件并下载/保存 - Create PDF file with byte array and download/save it 从服务器下载Excel文件并保存在客户端上 - Download Excel file from server and save on client
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM