[英]How to force download of "index.html" file via an <a> tag in HTML
我最終得到了這個解決方案 - 歡迎任何改進它的輸入。 請注意,除非index.html
位於同一域中,否則此解決方案會導致 CORS 問題,但由於對我來說恰好是這種情況,因此它可以根據需要工作。
HTML:
<a href="#" id="download-editor" class="btn-white">Offline editor</a>
Javascript:
<script>
window.onload = function() {
var a = document.getElementById("download-editor");
a.onclick = function() {
var url = 'https://canlogger.csselectronics.com/simple-editor/index.html'
fetch(url).then(function(t) {
return t.blob().then((b)=>{
var a = document.createElement("a");
a.href = URL.createObjectURL(b);
a.setAttribute("download", 'config-editor.html');
a.click();
}
);
});
}
}
</script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.