.html下载本地
通过javascript实现
index.html
<ahref=#onclick="window.open('temp.html');return(false);">下载文件</a>
#######
temp.html//被下载文件
<Scriptlanguage="javascript">
if(typeof(window.opener)!='undefined')//判断打开方式的下载。去掉会一打开文件就弹出下载框
{
document.execCommand('SaveAs');
window.close();
}
</Script>
################
<buttononclick="javascript:document.execCommand('SaveAs');">保存本页面</button>
通过javascript实现
index.html
<ahref=#onclick="window.open('temp.html');return(false);">下载文件</a>
#######
temp.html//被下载文件
<Scriptlanguage="javascript">
if(typeof(window.opener)!='undefined')//判断打开方式的下载。去掉会一打开文件就弹出下载框
{
document.execCommand('SaveAs');
window.close();
}
</Script>
################
<buttononclick="javascript:document.execCommand('SaveAs');">保存本页面</button>
本文介绍了一种利用JavaScript在浏览器环境中实现HTML文件下载的方法。通过`document.execCommand('SaveAs')`命令触发文件保存对话框,使得用户可以直接下载当前页面为HTML文件。此方法适用于不需要复杂后端支持的轻量级文件分享场景。
103

被折叠的 条评论
为什么被折叠?



