我想通过JavaScript在我的网站上下载资源。这是我目前拥有的代码:.PDF和.JPG资产没有用JavaScript下载?
//Creates an iFrame and adds ID to it to download
var downloadURL = function downloadURL(url) {
var hiddenIFrameID = 'hiddenDownloader',
iframe = document.getElementById(hiddenIFrameID);
if (iframe === null) {
iframe = document.createElement('iframe');
iframe.id = hiddenIFrameID;
iframe.style.display = 'none';
document.body.appendChild(iframe);
}
iframe.src = url;
};
这将创建一个iframe,如果没有出现,给人的iFrame的“hiddenIFrameID”,并将其下载,客户端的ID。目前正在下载.psd和.ai文件,但在下载.jpg或.pdf文件时无法解释该文件。有什么建议?这是我的HTML结构:
<a onclick="downloadURL('imagepath.jpg');">Download</a>
如果浏览器可以呈现它们,它可能只显示iframe中的文件。哪些赢得了PSD或AI文件发生。 – putvande
您需要访问服务器端才能更改文件的标题。 – SeanKendle
没有服务器,这是所有本地(文件://) –