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