代碼如下:
//保存聊天記錄到本地
function save_record()
{
//取得當前日期作為文件名
var time=new Date();
var filename=time.toLocaleDateString();
//獲取當前頁面部分內容
var record=$("#contentList").html();
//打開新窗口保存
var winRecord=window.open('about:blank','_blank','top=500');
winRecord.document.open("text/html","utf-8");
winRecord.document.write("<html><style>body,ul,li{margin:0px; padding:0px;list-style:none; font-size:12px;}</style><body>"+record+"</body></html>");
winRecord.document.execCommand("SaveAs", true, filename+".html");
winRecord.close();
}