0

I run into issue what ie7 doesn't support blob data type.
And now i can't force browser(ie7) to load file which i pass from server with get request.
Modern browsers(chrome, firefox) do it well with this js code

        var xhr = new XMLHttpRequest();
        xhr.open('GET', COEFF_CONTROL_GET_CSV_FILE_URL + "&" + "DWL_PERIOD=2019&DWL_MR=37", true);
        xhr.onreadystatechange = function(){
            if(xhr.readyState == 4 && xhr.status == 200){
               //Code below implements file load
                var contentDisposition = xhr.getResponseHeader('content-disposition');
                var filename = contentDisposition.split("filename=")[1].split(";")[0];

                var blob = new Blob([xhr.response], {type: 'text/csv'});
                var link = document.createElement('a');
                link.href = window.URL.createObjectURL(blob);
                link.download = filename;

                document.body.appendChild(link);
                link.click();                    
            }
        }

Headers that i pass with my request from server for now

header("Content-Type", "text/csv;charset=utf-8");
header("Content-Disposition", "attachment;filename=&mvFileName");

I tried already(but it did't help)

Will be appreciate for all possible help!

  • It's time to leave Internet Explorer in the dust. It's been discontinued for a while. – StackSlave Mar 11 '20 at 20:24
  • You just want to click a link and force download? [Example #1](https://www.php.net/manual/en/function.readfile.php#example-2963) – StackSlave Mar 11 '20 at 20:29
  • @StackSlave, can't use anything but ie7 unfortunately( – Vladislav Yun Mar 12 '20 at 11:02
  • @StackSlave I want to handle request from srv with csv file inside it and load this file on disk – Vladislav Yun Mar 12 '20 at 11:09
  • Saving the file itself to the Browser is not possible in ie7... [FlieSystemFileEntry](https://developer.mozilla.org/en-US/docs/Web/API/FileSystemFileEntry) is not supported by IE at all. You could use the `XMLHttpRequest` to get the file as `XMLHttpRequestInstance.responseText`, but it would be a String that you would have to parse. Personally, I would use JavaScript to send an `XMLHttpRequest` to PHP, then use [str_getcsv](https://www.php.net/manual/en/function.str-getcsv.php#V114764), having a response just like that example, except you `echo json_encode($csv);`. – StackSlave Mar 12 '20 at 22:34
  • @ВладиславЮн, If you think my suggestion can be the answer to this question then I suggest you accept it as an answer. It can help other community members in the future in similar kinds of issues. Thanks for your understanding. – Deepak-MSFT Mar 16 '20 at 09:04

1 Answers1

0

You are using the IE 7 browser which is too old and out of support scope of Microsoft.

As Blob is not supported in IE 7, your code will not be going to work for IE 7 version.

I suggest you use the latest Microsoft browsers. If you are not able to use the latest Microsoft browsers then at least move to IE 11 version. Blob is supported from IE 10 version.

For the IE 11 browser, I suggest you make a test with Navigator.msSaveBlob() method.

The Navigator.msSaveBlob() method saves the File or Blob to disk. This method behaves in the same way as Navigator.msSaveOrOpenBlob() except that this disables the file open option.

Example:

var blob = new Blob(["Sample String\r\n,For Checking, msSaveBlob"],{
    type:'text/csv;charset=utf-8;'
});

if(navigator.msSaveBlob){
    navigator.msSaveBlob(blob,"sample.csv");
}

References:

  1. msSaveBlob

  2. msSaveBlob method

Deepak-MSFT
  • 10,379
  • 1
  • 12
  • 19