Click here to Skip to main content
15,880,469 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
In my web application i have an option to export "jqxgrid" data to ".CSV" format.

It is working as expected in Chrome & Firefox browsers. But, if, I tried the export option in 'Safari' browser it is opening it is in another tab, instead of download it as a separate file.

Is it possible to download it as a separate file?

Sample Code:
---------------------


JavaScript
 $("#gridExport").click(function () {
        exportData = [];
        var exportType = GetExportFormat(); //csv (or) xls
        exportInfo = $("#jqxgrid").jqxGrid('exportdata', exportType);
        exportInfo = replaceAll(exportInfo, '<br/>', ' ');
        try {
            var prm = {};
            prm.exportInfo = exportInfo;
            saveMyFile("$('SubmitForm')", "Test" + "." + exportType, exportInfo, "text/" + exportType + ";charset=utf-8");
        }
        catch (e) {
            console.log('Export Error: ' + e);
        }
    });


function saveMyFile(ref, fname, text, mime) {
    try {
        var blob = new Blob([text], { type: mime });
        saveAs(blob, fname);
        return false;
    } catch (e) {
        console.log('saveMyFile: ' + e.message);
    }
}



function GetExportFormat() {    
    var strPlatform = navigator.platform;
    if (strPlatform.toLowerCase().indexOf('ipad') > -1 || strPlatform.toLowerCase().indexOf('iphone') > -1 || strPlatform.toLowerCase().indexOf('mac') > -1)
        return "csv";
    else
        return "xls";
}


What I have tried:

Also, I have tried these below

Browser Settings -->
Privacy -->
Block cookies:
Never

Limit website access to location services:
Deny without prompting
Posted
Updated 9-May-16 22:50pm
v4
Comments
Michael_Davies 9-May-16 8:58am    
That behaviour is controlled by the browser, have you checked the setting in the browser,

Google gives: http://browsers.about.com/od/safar1/ht/safarisafefiles.htm
S.Krishnamoorthi 9-May-16 9:12am    
Yeah,

I have tried that too. It is also not working..

Also, I have tried these below too. ( It is also not working as expected)

Privacy -->
Block cookies:
Never

Limit website access to location services:
Deny without prompting

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900