[英](Javascript) How to force the download of an image using iframe?
我的要求是選擇一堆圖像並同時下載所有圖像。
我正在使用該庫( https://github.com/biesiad/multiDownload ),該庫與iamges之外的其他文件都可以很好地工作。 當它是圖像時,它將不起作用。
我的結論是,瀏覽器對圖像的感知不同於其他二進制文件。
我已經檢查了Google Chrome瀏覽器和使用該插件的所有文件,但這些文件都被取消了(開發人員工具>網絡),但是圖像卻沒有。
有沒有辦法告訴瀏覽器它和其他文件一樣是二進制文件? 有什么辦法嗎?
非常感謝
該函數是這樣實現的:
var methods = {
_download: function (options) {
var triggerDelay = (options && options.delay) || 100;
var cleaningDelay = (options && options.cleaningDelay) || 1000;
this.each(function (index, item) {
methods._createIFrame(item, index * triggerDelay, cleaningDelay);
});
return this;
},
_createIFrame: function (item, triggerDelay, cleaningDelay) {
setTimeout(function () {
var frame = $('<iframe style="display: none;" ' +
'class="multi-download-frame"></iframe>');
frame.attr('src', $(item).attr('href') || $(item).attr('src'));
$(item).after(frame);
setTimeout(function () { frame.remove(); }, cleaningDelay);
}, triggerDelay);
}
};
$.fn.multiDownload = function(options) {
return methods._download.apply(this, arguments);
};
更新:Github上multiDownload上的README.md說...
重要說明:所有$('。my_links')元素必須已定義“ href”屬性。 “ href”必須指向生成正確的HTML標頭的文檔(“ Content-Disposition:附件; filename = my_filename”)。
解決方案? 他們說了什么:發出以下標頭:
Content-disposition: attachment; filename="picture.jpg"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.