1
以下HTML文件在Chrome中打開時下載test.gif文件。在Firefox/IE上,沒有任何反應。動態創建的鏈接在Chrome瀏覽器中工作,但不在Firefox或IE中
<html>
<head>
<script type="text/JavaScript" language="JavaScript">
function s() {
var link = document.createElement('a');
link.download = "test.gif";
link.href = 'http://192.168.20.22/mantis/images/mantis_logo.gif';
link.click();
}
</script>
</head>
<body onload="s()" >
</body>
</html>
螢火告訴我,鏈接對象是正確創建和HREF設置,但不知何故,在調用link.click()什麼也不會發生。任何想法爲什麼?
檢查鏈接http://stackoverflow.com/問題/ 29494715/jQuery的文件下載 - 作品 - 在 - 鉻 - 但並非Firefox瀏覽器。它可能會幫助你解決問題。 – Pramod
您需要將鏈接添加到正文。這是你需要的:http://stackoverflow.com/questions/3665115/create-a-file-in-memory-for-user-to-download-not-through-server/20194533#20194533 –
也檢查這個問題:http://stackoverflow.com/questions/809057/how-do-i-programmatically-click-on-an-element-in-firefox很多答案會給你提示如何繼續 – valepu