JavaScript默认下载名称

时间:2018-10-19 08:59:10

标签: javascript jsp download

我需要将默认文件名从文件的“类型”更改为视频的标题。标题位于.jsp文件中,名为:

<c:set var="rawTitle" value="${video.title}" />

下面是我需要更改的下载功能。

// Function to generate the Download button
VideoPlayer.prototype.initDownload = function () {

var downloadBtn         = $("button.download"),
    downloadToolTipCls  = "download_tooltip",
    sources             = {},
    downloadToopTip,
    sourcesLength = 0,
    sourcesKeys;


// Add each source
if (typeof (firstSrc = this.$video.attr("src")) !== "undefined") {
    sources[firstSrc] = this.$video.attr("type");
}

this.$video.find("source").each(function () {
    var $this = $(this);
    sources[$this.attr("src")] = $this.attr("type");
});

sourcesKeys = Object.keys(sources);
sourcesLength = sourcesKeys.length;
if (sourcesLength === 1) {
    downloadBtn.wrap("<a href=\"" + sourcesKeys[0] + "\" download />");
} else if (sourcesLength > 1) {
    downloadBtn.after("<span class=\"" + downloadToolTipCls + "\" />");
    downloadToopTip = $("." + downloadToolTipCls);

    $.each(sources, function (source, type) {
        downloadToopTip.append("<a href=\"" + source + "\" download> Type " + type + "</a>");
    });

    downloadBtn.click(function () {
        downloadToopTip.toggle();
    });
}
};

0 个答案:

没有答案