六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 101|回复: 0

用js保存页面指定内容、指定文件类型

[复制链接]

升级  23.33%

23

主题

23

主题

23

主题

秀才

Rank: 2

积分
85
 楼主| 发表于 2013-2-7 19:34:16 | 显示全部楼层 |阅读模式
 
用js保存页面指定内容
 
转自:  http://rorchina.iteye.com/blog/184425
 
<script language=javascript>   function Save(){       var txt = document.all.output.value;    b = window.open();      b.document.open();      b.document.write(txt);      b.document.close();    b.document.execCommand('saveas',true,'output.html');    b.window.close();}</script> <center>仅保存文本框中部分:</center><table width="90%" align="center" border="0" cellpadding="0" cellspacing="0">     <tr> <td>不保存</td> <td><input type="button" value="Save" class="trans" ><textarea rows="20" cols="50" id="output" class="txtedit"></textarea></td>     </tr> </table>  
 
保存HTML中的Table到Excel中
 
转自:http://www.bcbbs.net/news/Content28841.aspx
 
<html>   <head>      <title>保存HTML中的Table到Excel中</title>   </head>   <body>      <h1>保存内容到Excel中</h1>      <table id='content'>          <tr><td>列1</td><td>列2</td></tr>          <tr><td>a1</td><td>a2</td></tr>          <tr><td>b1</td><td>b2</td></tr>          <tr><td>c1</td><td>c2</td></tr>          <tr><td>d1</td><td>d2</td></tr>          <tr><td>e1</td><td>e2</td></tr>          <tr><td>f1</td><td>f2</td></tr>      </table>       <a href="javascript:downloadfile('content')">保存文件</a>     <script language="javascript">        function downloadfile(id)        {                window.document.write(document.getElementById(id).outerHTML);                window.document.execCommand("SaveAs",false,"C:\\download.xls");                history.go(-1);        }      </script>   </body> </html>    
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表