在浏览器中,当您要保存当前正在查看的HTML页面时,通常会转到“文件”菜单并单击“另存为” .
我可以在HTML页面底部有一个小按钮来执行相同的操作吗?因此,我没有进入“文件”菜单 - >“另存为”,而是希望我的用户能够单击按钮将页面保存到磁盘上 .
据我所知,存在使用Javascript的解决方案,但它仅适用于IE . 看这里:link text
您必须创建一个按钮来下载HTML文件或您所在的页面:
<form><input type="button" value="Download Now" onClick="window.location.href='yourpage.html'"></form>
您可以让链接运行服务器端脚本,该脚本加载HTML文件并使用 Content-Disposition: attachment; filename=xxx.html 标头将其写回客户端 .
Content-Disposition: attachment; filename=xxx.html
document.execCommand('SavaAs') 仅适用于IE,但以下链接提示您可能想要尝试的其他可能性 .
document.execCommand('SavaAs')
Here is the answer to that :)
看看downloadify jQuery插件,它使用flash保存 . 单凭Javascript是不可能的 .
4 回答
您必须创建一个按钮来下载HTML文件或您所在的页面:
您可以让链接运行服务器端脚本,该脚本加载HTML文件并使用
Content-Disposition: attachment; filename=xxx.html
标头将其写回客户端 .document.execCommand('SavaAs')
仅适用于IE,但以下链接提示您可能想要尝试的其他可能性 .Here is the answer to that :)
看看downloadify jQuery插件,它使用flash保存 . 单凭Javascript是不可能的 .