Download file in javascript is not working in Chrome
below is the code
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);
}
its working in all browser except chrome.
I have used frame also as below code but it does't work in case of huge data..
function Download(url) {
try {
$("#fileIframe").html("");
var iframe = $('<iframe name=开发者_Python百科"postframe" id="postframe" class="hidden" frameBorder="0" src="about:none" />');
$('#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)
}
}
Here is the way we export an excel file using an IFRAME
:
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;
};
}
It works in all browsers, and has the advantage of not popping up a window.
Try the following:
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.*/}
}
I think it may be down to the moveTo() method as Chrome is a pure tabbed browser.
Also try check out the window.resizeTo(100,100)
精彩评论