javascript中的下载文件无法在Chrome中运行

下面是代码

function ExportToExcel() { if ($("#dateRange").val() != "") { var frm = $("#frmProjectReport").serialize(); var url = "/Reports/ProjectExcelReport?" + frm; Download(url); } } function Download(url) { alert(url); //var win = window.open(url, "DownloadWin", "resizable=0,status=0,toolbar=0,width=600px,height=300px"); var win = window.open(url, "DownloadWin", "width=600px,height=300px,scrollbars=yes ,menubar=no,location=no,left=0,top=0") win.focus(); win.moveTo(100, 100); } 

它在除Chrome之外的所有浏览器中工作。

我也使用框架作为下面的代码,但它不适用于大数据的情况..

  function Download(url) { try { $("#fileIframe").html(""); var iframe = $(''); $('#fileIframe').append(iframe); $('#frmProjectReport').attr("action", url); $('#frmProjectReport').attr("method", "post") $('#frmProjectReport').attr("target", "postframe") $('#frmProjectReport').submit(); //win = window.open(url, "DownloadWin", "width=600px,height=300px,scrollbars=yes ,menubar=no,location=no,left=0,top=0") //win.focus(); //win.moveTo(100, 100); } catch (e) { alert(e) } } 

以下是使用IFRAME导出excel文件的方法:

 function download(src){ var ifr = document.createElement('iframe'); ifr.style.display = 'none'; document.body.appendChild(ifr); ifr.src = src; ifr.onload = function(e){ document.body.removeChild(ifr); ifr = null; }; } 

它适用于所有浏览器,并且具有不弹出窗口的优点。

请尝试以下方法:

 function Download(url){ try { var win = window.open(url,"DownloadWin","width=600px,height=300px,scrollbars=yes ,menubar=no,location=no,left=0,top=0"); try { win.focus(); win.moveTo(100, 100); }catch(e){/*Focus|moveTo not supported*/} }catch(e){/*open not supported, doubt it.*/} } 

我认为这可能取决于moveTo()方法,因为Chrome是纯标签式浏览器。

另请尝试查看window.resizeTo(100,100)