代码之家  ›  专栏  ›  技术社区  ›  TomáÅ¡ Zato

在Firefox中初始化IFRAME下载后出现奇怪的浏览器错误对话框

  •  0
  • TomáÅ¡ Zato  · 技术社区  · 6 年前

    当我尝试从隐藏的 <iframe> 元素:

    enter image description here

    你上面看到的不是 alert() . 这是一个本地浏览器对话框,一个我从未见过的。

    代码很简单。它在GWT代码中嵌入了javascript:

    protected native void downloadLink(String url, IframeOnError onError, IframeOnSuccess onSuccess)/*-{
        console.log(url, onError, onSuccess);
        var tmpIframe = document.createElement("iframe");
    
        tmpIframe.style.position = "absolute";
        tmpIframe.style.width = "5px";
        tmpIframe.style.height = "5px";
        tmpIframe.style.top = "-10px";
        tmpIframe.onload = function() {
            console.log("Success cb:",onSuccess);
            onSuccess();
            document.body.removeChild(tmpIframe);
        };
        tmpIframe.onerror = function() {
            console.log("Error cb:",onError);
            onError();
            document.body.removeChild(tmpIframe);
        };
        console.log("Appending download <iframe>!",tmpIframe);
        tmpIframe.src = url;
        document.body.appendChild(tmpIframe);
    }-*/;
    

    我可以在开发工具中看到服务器的响应。标题如下:

    HTTP/1.1 200 OK
    Date: Tue, 29 Jan 2019 13:43:11 GMT
    Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
    Content-Disposition: attachment; filename="denni.xlsx"
    Content-Length: 87966
    

    我在其他浏览器中没有遇到过这样的事情。其他浏览器正常工作。

    0 回复  |  直到 6 年前