下载当前的html文件 [英] Download current html file

查看:60
本文介绍了下载当前的html文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何让用户下载当前的html页面?该网页使用ajax加载文本,因此我的代码不起作用,因为它下载了页面的原始状态:

How is it possible, to let the user download the current html page? The webpage loads the text using ajax, so my code doesn't works, because it downloads the original state of the page:

<a href="URL_OF_THIS_PAGE" download="page.html">Download</a>

推荐答案

<a onclick="this.href='data:text/html;charset=UTF-8,'+encodeURIComponent(document.documentElement.outerHTML)" href="#" download="page.html">Download</a>

这篇关于下载当前的html文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆