1

the code works fine in chrome, however in IE11 it says Script5 access denied at a.click()

    success: function (data) {
    var data1 = data['csv_string'];
    filename = data['filename'];

    const blob = new Blob([data1],{type: 'text/csv'});
    const url = window.URL.createObjectURL(blob);

    const a = document.createElement('a');
    a.setAttribute('hidden','');
    a.setAttribute('href',url);
    a.setAttribute('download',data['filename']);
    document.body.appendChild(a);
    a.click();
  • Welcome! So? If it works on Chrome = you're good to go! – iAmOren Oct 25 '20 at 12:09
  • @iAmOren not, unfortunately, if you still have users on IE! – A Haworth Oct 25 '20 at 12:40
  • @AHaworth, Chrome is at 69.19% of market share of browsers. #2 is FireFox at 7.60% and is negligible as well as all the rest which have even lower share. If, in the future, a new browser will take-over, it better be compliant with Chrome, so, even then, IE (and any other "browser" other than Chrome) support is a waste of time. As an exercise in antiquity, make it work on the previous king - NetScape... – iAmOren Oct 25 '20 at 14:51
  • Hi @iAmOren it depends on what your users use. I agree Chrome has a large share, and Edge will probably gain some as it's basically the same. My situation is that I run websites for a few little charities, one at least of which has an elderly membership some of whom who are using PCs donated from friends and they would not want to learn about installing new software. It depends on who your audience is whether you need to create for IE or not. The situation will pass with time but it's not gone for me at least just yet. – A Haworth Oct 25 '20 at 15:32

3 Answers3

0

Apparently Internet Explorer anchor (a) element does not support the download attribute. see e.g. https://caniuse.com/?search=download

You can download your blob using IE but you have to use navigator.msSaveOrOpenBlob so try testing if that function exists, and if it does use it else do what you are doing now.

   if (navigator.msSaveOrOpenBlob) {
        navigator.msSaveOrOpenBlob(...your stuff to save in the format for this function);
        }
    else {
    ....what you are doing now...
    }
A Haworth
  • 30,908
  • 4
  • 11
  • 14
0

You will not be able to download the Blob file in the IE browser using the code posted in the original post.

You need to specifically use the msSaveBlob or msSaveOrOpenBlob to download the blob in the IE browser.

navigator.msSaveBlob(blob, defaultName);

OR

navigator.msSaveOrOpenBlob(blob, defaultName);
Deepak-MSFT
  • 10,379
  • 1
  • 12
  • 19
-2

Internet explorer is dying. I'd suggest not bothering to optimize for ie, and display a warning to use a diffrent browser. Unless you absolutely need it.

  • 2
    While it's true that IE is dying this isn't too helpful for those of us who have users (often elderly and/or on secondhand machines - especially in the charity world) who are stuck on IE. – A Haworth Oct 25 '20 at 10:35
  • @AHaworth True, that's why I asked if he needed it. There are obviously still people using ie. I'm just saying it's not worth it to optimize for ie if his target group doesn't use it. – remcoland59 Oct 25 '20 at 12:00
  • 1
    I'd recommend spending the energy needed to coerce code to IE, on helping people who don't know better and still use IE - to learn to and start to use a real browser. Chrome is my recommendation. – iAmOren Oct 25 '20 at 12:11