我正在控制台上测试以下一段 Javascript 代码,然后将其包含到我的应用程序中(我在 SO 上找到了它)
pom = document.createElement('a')
pom.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent("Hello World!"))
pom.setAttribute('download', "IEpomTest")
pom.style.display = 'none'
document.body.appendChild(pom)
pom.click()
document.body.removeChild(pom)
这在 Chrome 上运行良好,并且 pom.click() 下载带有“Hello World!”的文本文件。但是当我在 IE11 上尝试时,“pom.click()”将我带到这个 URL“data:text/plain;charset=utf-8,Hello%20World!”我收到错误消息“无法显示网页”。
有人知道我做错了什么吗?
最佳答案
IE 将尝试作为网站打开,更好的方法可能是检查 window.navigator.msSaveBlob
是否存在,如果存在,Using this method to download the file
关于javascript - click() 在 Chrome 中工作正常,但在 IE11 中不行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43988862/