"wget http://www.example.com/file.doc http://www.example.com/file.doc" 将该文件下载到本地磁盘。
在 javascript 中,上面的等价物是什么?例如,考虑以下 html 片段。
<html>
<head>
<script language="JavaScript">
function download_file() {
var url = "http://www.example.com/file.doc"
//
// Question:
//
// what should be done here to download
// the file in the url?
//
}
</script>
</head>
<body>
<input type="button" value="Download" onclick="download_file()">
</body>
</html>
请建议一个与所有浏览器兼容的解决方案。
桑吉斯。
经过一个多月的摸索,在朋友的帮助下,我们得到了以下信息。
托管该文件的网站不允许我们使用以下方式下载该文件window.location = url;
or window.open(url);
最后我们不得不使用data-downloadurl
来自的支持HTML5
如下
<a href="<url-goes-here>" data-downloadurl="audio/mpeg:<filename-goes-here>:<url-goes-here>" download="<filename-goes-here>">Click here to download the file</a>
我们将此 html 嵌入到主机 html 中,当单击该链接时,它会触发下载。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)