在客户端下载本地 html 文件

download local html file on client side

我有一个名为 test.html 的本地文件。该文件的路径(相对)是“../slides/test.html”.

我愿意:

我该怎么做这两件事?

我试图用 ajax 获取文件,我得到了包含文件 html 代码的数据对象,但我不知道如何下载和打开这个文件。

$.ajax({
    url: "../slides/test.html",
    success: function(data){
        alert(data);
    }
});

更新

我这样做解决了问题:

<ul class="buttonsList">
    <li><a href="#" id="fullscreenBtn">View in fullScreen</a></button></li>
    <li><a href="#" id="downloadBtn" download>Download</a></button></li>
</ul>

// Register click on download button
$("#downloadBtn").off().on('click', function() {
    var slideURL = $(".helpActive").attr("data-textTour-url");
    $('#downloadBtn').attr({href  : slideURL});
});

// Register click on download button
$("#fullscreenBtn").off().on('click', function() {
    var slideURL = $(".helpActive").attr("data-textTour-url");
    $('#fullscreenBtn').attr({target: '_blank', href  : slideURL});
});

下载

<a href="path-to-file" download>Download</a>

在新标签页中打开

<a href="path-to-file" target="_blank">Open in new tab</a>