简体   繁体   English

使用javascript客户端将div内容另存为.txt或PDF文件

[英]save div content as .txt or PDF file with javascript Client-Side

me using asp.net mvc as technology behind. 我使用asp.net mvc作为背后的技术。 how can i use JavaScript for saving content of div "bla bla" as Txt or PDF Document on Client-side ? 如何在Client-side使用JavaScript将div“ bla bla”的内容另存为Txt or PDF Document something like this?? 像这样的东西? if yes, how can i do it? 如果是,我该怎么办? me not very strong in javascript :( 我的JavaScript不是很强大:(

<div id="Overview">bla bla</div>
<input type="button" id="SaveAsTxt" onclick="JavaScript:SavePartOfPageAsTxt('Overview');"/></div>

 <script type="text/javascript">
<!--
        function SavePartOfPageAsTxt(elementId) {
        }
// -->
</script>

Do you want to save the text file on the client or the server? 您要将文本文件保存在客户端还是服务器上?

For saving to the server, use Javascript to send the data to the server code and use your server code to save it. 要保存到服务器,请使用Javascript将数据发送到服务器代码,然后使用服务器代码进行保存。

For saving to the client, you might have a problem getting access to the client's machine (and rightly so), however, you can do it with an ActiveX control or Flash (not ideal), or even save it as a cookie. 为了保存到客户端,访问客户端计算机可能会遇到问题(正确的做法是),但是,可以使用ActiveX控件或Flash(不理想)进行保存,甚至将其保存为Cookie。

Another option if you wanted to use jQuery is this plugin: http://www.filamentgroup.com/lab/jquery_plugin_for_requesting_ajax_like_file_downloads/ - this will ask the client if they're happy to save the file. 如果您想使用jQuery,则另一个选择是此插件: http : //www.filamentgroup.com/lab/jquery_plugin_for_requesting_ajax_like_file_downloads/-这将询问客户端是否愿意保存文件。

EDIT: Close duplicate of Read/write to file using jQuery - the same applies for Javascript/jQuery. 编辑: 使用jQuery关闭对文件读/写的重复项-Java / jQuery也是如此。

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

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