javascript - 如何下载当前网页
问题描述
我想添加一个按钮来下载我的网页的 html 源代码,我能够做到,但问题是当我添加 localhost url 时它可以工作,但是当我添加 live url 时它打开的是 url 而不是下载它。到目前为止我试过这个
<a download href="http://localhost/test-new/">Download Source Code</a>
我也试过这个
<button onclick="clicker()">Click me</button>
<script type="text/javascript">
function clicker() {
var anchorTag = document.createElement('a');
anchorTag.href = "http://localhost/test-new/";
anchorTag.download = "download";
anchorTag.click();
var element = document.getElementById('divContainer');
element.appendChild(anchorTag);
}
</script>
这两者都在本地主机中工作,但不适用于实时网址。请帮我
解决方案
您可以使用
document.querySelectorAll('*')
获取网页的源代码
console.log(document.querySelectorAll('*'))
推荐阅读
- java - 如何解决 JavaFX 使用弹出通知的问题
- python - 熊猫:如何累积回报 - 预测价格
- javascript - 哪些组件正在添加情感 css 全局样式
- java - 无法通过 Java 代码执行 java -jar 命令
- python - 通过 UDP 发送浮点结构
- r - 如何从收益率曲线中获得不同的期限
- javascript - 反应触发器调整大小但实际上并没有调整屏幕大小
- maven - 如果服务器需要基本身份验证,如何访问 sonarqube?
- spring-mvc - 如何在 @Before 方法中将 Principal 设置为 RestAssuredMockMvc 或 MockMvc?
- android - 发布版本时 CardViews 中的空 TextViews