点击()可以在Chrome中正常工作,但不能在IE11中正常工作 [英] click() works fine in Chrome but not in IE11
问题描述
我在控制台上测试了以下一段Javascript代码,然后将其包含在我的应用程序中(我在它上面找到了它)
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()会将我带到此URLdata:text / plain; charset = utf-8,Hello%20World!我收到错误消息网页无法显示。
任何人都有一个想法我做错了什么?
I'm testing the following piece of Javascript code on the Console before I include it into my application (I found it on 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)
This is working fine on Chrome and the pom.click() downloads a text file with "Hello World!" in it, but when I try it on IE11, the "pom.click()" takes me to this URL "data:text/plain;charset=utf-8,Hello%20World!" and I get the error message "The webpage cannot be displayed".
Anyone has an idea what am I doing wrong?
IE will try to open as a website, a better approach might be checking if window.navigator.msSaveBlob
is present, and if is, Using this method to download the file
这篇关于点击()可以在Chrome中正常工作,但不能在IE11中正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!