N
N
Nick Fisher2019-01-31 09:18:12
JavaScript
Nick Fisher, 2019-01-31 09:18:12

How to implement a link to download a file?

Good morning. You need to make a link to download the file. The problem is that it should work in ie 11 and this implementation, alas, is not suitable.

const download = filename, text) => {
    let element = document.createElement('a');
    element.setAttribute('href', 'somelink' + text);
    element.setAttribute('download', filename);
    document.body.appendChild(element);
    element.click();
    document.body.removeChild(element);
  }

What can you advise? In chrome, everything works fine with and without the download attribute.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
Petr Vasiliev, 2019-01-31
@danial72

https://m.habr.com/ru/post/151795/
Give the server a file

P
Pavel Volintsev, 2019-01-31
@copist

Your sample code doesn't affect the download at all. IE may not like you doing a click() on an element. Perhaps opening a link in an iframe will work

C
coderisimo, 2019-01-31
@coderisimo

IE (the most advanced browser!) does not support the Download attribute in "a" tags.
proof
here is an article in Russian about a possible solution
Where to dig

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question