在项目开发中,碰到了一个最简单不过的问题,但是解决起来也很头疼的问题。现在记录下来。以做以后参考。。。
项目中,所有字符集设置成 UTF-8。
但是在页面中,需要把一部分文字。以另存为的形式存储下来。。(现只解决IE)
做法如下
第一步:在JSP页面,做一个IFRAME。具体如下
<iframe name="winaa" style="display:none"></iframe>
第二步:
js
var fileName="另存为测试.txt"; var winaa = window.open("","winaa","width=0,height=0,top=10000,left=10000,alwaysLowered=yes"); winaa.document.open("text/html","replace"); winaa.document.charset="UTF-8"; winaa.document.write("这只是一个测试用例子"); winaa.document.execCommand("SAVEAS",false,fileName); winaa.close();
对于有中文的另存为就已经OK了,当然了,如果只是保存字母数字,也有更简单的写法。。可以上网搜下。。这里只做一下记录