简体   繁体   English

IE 8 fireEvent未指定错误

[英]IE 8 fireEvent Unspecified error

I get through ajax call some text file and I need to save it on client side, I found a code that helped me with this (it's working in Opera, Chrome, FireFox), but in IE 8 it doesn't want to working, I'm getting "Unspecified error" in fireEvent line. 我通过ajax调用了一些文本文件,并且需要将其保存在客户端,我找到了一个可以帮助我解决此问题的代码(它可以在Opera,Chrome,FireFox中运行),但是在IE 8中,它不想运行,我在fireEvent行中收到“未指定的错误”。 Could you help me to understand, what is wrong? 您能帮我了解一下,什么地方错了?

var url = 'data:application/octet-stream,' + responseData;
                var anchor = document.createElement('a');
                anchor.setAttribute('href', url);
                anchor.setAttribute('download', fileName);

                var e;
                if (document.createEvent) {
                    var e = window.document.createEvent("MouseEvents");
                    e.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
                    anchor.dispatchEvent(e);
                } else if (window.document.createEventObject) {
                    try {
                        var clickEvent = document.createEventObject();
                        clickEvent.button = 1;
                        anchor.fireEvent('onclick', clickEvent); // <-- there is error "Unspecified error"

                    } catch (ex) {
                        alert(ex);
                    }

                }

这可能是因为目标元素不在文档中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM