views:

48

answers:

2

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="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)
            }
        }
A: 

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.

Mic
Thanks Mic for your response.but this also caused problem when the data is very large in serialize object.At that situation nothing is happen.In my case data is in very huge amount.
Amit
The amount of data you send with a GET request(in the url) is limited and depends on the browser. If it is huge, you need to first call your backend with a POST, receive an id and then make the GET call with this id.
Mic
ok thanks Mic... Let me check again...
Amit
A: 

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)

RobertPitt
i had tried this also robert,but it did't work for me.Thanks for response.
Amit