函数onclick javascript在Microsoft Edge中不起作用

时间:2018-11-14 14:54:14

标签: javascript ajax

我已经完成了onclick的功能,可以在我们的网站上下载pdf。 除了此ajax消息外,Chrome和Mozilla都可以正常运行(不赞成使用主线程上的Synchronous XMLHttpRequest,因为它会对最终用户的体验产生不利影响。) 但是,当我在Microsoft Edge中单击该按钮时,该按钮不起作用。谁能帮我?我的代码在下面。

<script>

function download_datasheet(uri, name) {



var modal = document.getElementById('myModal');  
            var span = document.getElementsByClassName("close")[0];  
            var nome;  

            nome = name + ".pdf";  
            modal = document.getElementById('myModal');  
            modal_content = document.getElementsByClassName("modal_texto")[0];  
            lang = window.location.href;  
            lang = lang.split("/");  
            console.log(lang[1]);  
            if(lang[1].includes("pt-pt"))  
            modal_content.innerHTML =  "<table border=\"0\"><tr><td style=\"width:80px; background-color:white\"><img src=\"/sites/default/files/Imagens_tecit/Tecit/wait2.gif\" alt=\"wait\"></td><td style=\"background-color:white; color:#5cb8e5; font-size:20px;\"><p class=\"descricao\">Loading...</p></td></tr></table>"  
            else modal_content.innerHTML = "<table border=\"0\"><tr><td style=\"width:80px; background-color:white\"><img src=\"/sites/default/files/Imagens_tecit/Tecit/wait2.gif\" alt=\"wait\"></td><td style=\"background-color:white; color:#5cb8e5; font-size:20px;\"><p class=\"descricao\">Loading...</p></td></tr></table>"
            modal.style.display = "block";  

            var HttpClient = function() {  
                this.get = function(aUrl, aCallback) {  
                    var anHttpRequest = new XMLHttpRequest();    
                    anHttpRequest.onreadystatechange = function() { 
                        if (anHttpRequest.readyState == 4 && anHttpRequest.status == 200)  
                            aCallback(anHttpRequest);  
                    }  
                    console.log(aUrl);  
                    anHttpRequest.open( "GET", aUrl, true );          
                    XMLHttpRequest.withCredentials = false;  
                    anHttpRequest.send( null );  
                    anHttpRequest.responseType = "blob";  
                }
            }  

            var client = new HttpClient();  
            function eei_terminado(ficheiro){  
                var blob = new Blob([ficheiro.response]);  
                var a = document.createElement("a");  
                a.style = "display: none";  
                document.body.appendChild(a);  
                var url = window.URL.createObjectURL(blob);  
                a.href = url;  
                a.download = nome;  
                a.click();  
                window.URL.revokeObjectURL(url);  
                modal.style.display = "none";  
            }  
            client.get(uri, function(response) {  
                eei_terminado(response);  
            });


        }

</script>

谢谢!

0 个答案:

没有答案