【发布时间】:2013-08-26 00:50:50
【问题描述】:
从下面的代码中,我创建了一个下载文件的动态锚标记。此代码在 Chrome 中运行良好,但在 IE 中运行良好。我怎样才能让它工作
<div id="divContainer">
<h3>Sample title</h3>
</div>
<button onclick="clicker()">Click me</button>
<script type="text/javascript">
function clicker() {
var anchorTag = document.createElement('a');
anchorTag.href = "http://cdn1.dailymirror.lk/media/images/finance.jpg";
anchorTag.download = "download";
anchorTag.click();
var element = document.getElementById('divContainer');
element.appendChild(anchorTag);
}
</script>
【问题讨论】:
-
第一次点击时为什么还要麻烦appendChild呢?广告为什么在可以执行 location=URL 时点击它
-
我认为创建新的 a 标签没有意义。为什么单击“单击我”按钮时不触发下载。网络用户不喜欢点击
标签: html internet-explorer anchor