描述:页面有三段文字,我想通过按钮分别保存为文件
问题:目前方法一:<input type=button value=另存为 name="rsa" onclick="document.execCommand(saveas,true,个人私钥.txt)">
会把页面所有文字都保存
方法二:<%@page contentType="text/html;charset=gb2312"%>
<%String rsaCer="AAAAAAAAAAAAAA";%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<script>
function bb(rsaCer)
{
w=window.open()
w.document.write(rsaCer)
w.close();
w.document.execCommand("SaveAs",true,"个人私钥.txt")
}
</script>
</head>
<body>
<input type="hidden" name="a" value="<%=rsaCer%>">
个人私钥:<input type=button value=另存为txt onclick="bb(<%=rsaCer%>)">
<%=rsaCer%>
个人证书:
BBBBBBBBBBBB
CA证书:
CCCCCCCCCCCCCCCCC
</body>
</html>
这样虽然可可以单独保存文字,但是会开一个新窗口,而且它的属性,我设置了还不能使他看不到
哪位仁兄有办法可以让新窗口隐藏或者其他办法解决问题就多多指教!!
跟着你的思路做可以这样:
w=window.open("", "", "left=1800,height=1000");
w.document.write(rsaCer);
w.document.execCommand("SaveAs",true,"个人私钥.txt");
w.close();
我这边好像要把w.close()放在后面才行
<input type=button value=另存为 name="rsa" onclick="test()">
<SCRIPT LANGUAGE="JavaScript">
<!--
function test(){
document.body.insertAdjacentHTML("beforeEnd","<iframe name=aaa id=aaa></iframe>");
aaa.document.write("123 asdf asdf asdf asf dasdf");
aaa.document.close();
aaa.document.execCommand(saveas,true,个人私钥.txt);
document.all("aaa").removeNode(true);
}
//-->
</SCRIPT>