如何强制JavaScript绑定图像链接以下载,而不是在同一选项卡中打开?

如何强制JavaScript绑定图像链接以下载,而不是在同一选项卡中打开?,javascript,jquery,href,jquery-events,Javascript,Jquery,Href,Jquery Events,我使用它将href绑定到li元素上的单击事件: $(".attachment_file", "#ADlist").each(function() { $(this).click(function() { document.location.href = "upload/Attachments/T" + urlParam('recsel') + "/" +$(this).attr("filename"); }); }); 问题是

我使用它将
href
绑定到
li
元素上的单击事件:

  $(".attachment_file", "#ADlist").each(function() {
        $(this).click(function() {
            document.location.href = "upload/Attachments/T" + urlParam('recsel') + "/" +$(this).attr("filename");
        });
    });
问题是,当文件名是图像时,它会打开该图像


我如何才能强制它下载而不是打开它?

我没有找到任何方法从JavaScript更改
内容类型
,这可能是不可能的(请参阅:),因此剩下的唯一一件事就是从
.htaccess
更改

我仍然可以在javascript中使用JQuery将
li
中的
div
更改为
a
锚定,并添加
下载
href
属性,但我选择了更简单的选项,图像将在新选项卡中打开:

$(".attachment_file", "#ADlist").each(function() {
    $(this).click(function() {
    url = "upload/TravelRequestAttachments/T" + urlParam('recsel') + "/" + $(this).attr("filename");
    window.open(url, '_blank');

    });
});

在实际链接上使用HTML5
download
属性。不确定是否可以使用JS强制下载。