【JavaScript】IEの場合のdownload属性の代替

【JavaScript】IEの場合のdownload属性の代替

IEの場合、aタグのdownload属性が効かず、ファイルのダウンロードできなかったため、その代替案についての覚え書きです(Drupalネタではないです)。

download属性

Excelファイルをダウンロードできるように、以下のようなリンクを作成し、ファイルがダウンロードできることを確認していたのですが、


<a download="Test.xlsx" href="/download/Test.xlsx">Test.xlsx</a>

IEの場合、これではダウンロードできないとのことで、その対応結果を以下に記します。

JavaScriptでの対応

ググったところ、JavaScriptで画像をダウンロードしたいの記事によると、JavaScriptを使えば、IEでもリンクからファイルのダウンロードができるとのこと。

上記の記事を参考にして、以下のJavaScriptを記述。


function downloadFile(uri,fileName,id) {

    // IEはdownload属性が効かないので分岐
    if (window.navigator.msSaveOrOpenBlob) {
        let xhr = new XMLHttpRequest();
        xhr.open('GET', uri);
        xhr.responseType = 'blob';
        xhr.onloadend = function() {
            if (xhr.status !== 200) {
                return false;
            }
            window.navigator.msSaveOrOpenBlob(xhr.response, fileName);
        };
        xhr.send();
    } else {
        let link = document.getElementById(id);
        link.href = uri;
        link.download = fileName;
    }
}


HTMLは、以下のように記述を変更し、IEでもファイルをダウンロードできるようになりました。


<a id="download1" href="javascript:void(0);" onclick="downloadFile('/download/Test.xlsx','Test.xlsx','download1');">Test.xlsx</a>

カテゴリー

コメント

hidden financial services deep web <a href="https://heineken-darkweb.com/ ">drugs darknet vendors </a> https://heineken-darkweb.com/ - florida darknet markets
名前
Arnoldinfop
dark web markets reddit <a href="https://kingdom-darkmarketplace.com/ ">access the black market </a> https://kingdom-darkmarketplace.com/ - what darknet markets are available
名前
Timothylen
darknet market script <a href="https://kingdommarketlink.com/ ">darknet market vendors search </a> https://kingdommarketlink.com/ - dark markets montenegro
名前
HenryMaync
dynabolts pills <a href="https://kingdomdarkmarket.com/ ">dark markets bosnia </a> https://kingdomdarkmarket.com/ - oniondir deep web link directory
名前
Davidinton
where to find onion links <a href="https://heinekendarkweb.com/ ">darknet drugs india </a> https://heinekendarknet.com/ - darknet sites
名前
Williamroubs
darknet список сайтов <a href="https://dark-market-kingdom.com/ ">black market url deep web </a> https://darkweb-kingdom.com/ - new onion darknet market
名前
BrettUttep
weed darknet market <a href="https://heinekenmarketurl.com/ ">how to pay with bitcoin on dark web </a> https://heinekenmarketurl.com/ - darknet market and monero
名前
AndrewTelve
legit onion sites <a href="https://heinekendarkmarketonline.com/ ">how to access the black market </a> https://heinekendarkmarketonline.com/ - top onion links
名前
EdwardOppow
darknet market sites <a href="https://heinekenmarket-link.com/ ">darknet links markets </a> https://heinekenmarket-links.com/ - tor2door darknet market
名前
JohnnyBiz
darknet market buying mdma usa <a href="https://darkmarket-heineken.com/ ">dark web link </a> https://darkmarket-heineken.com/ - buy drugs darknet
名前
DanielNoubs
darknet market busts <a href="https://heinekenonion.com/ ">dark web website links </a> https://heinekenonion.com/ - what are darknet drug markets
名前
Zacharywah
cp onion <a href="https://kingdom-onion.com/ ">darknet market reddit list </a> https://kingdom-onion.com/ - deep dark web markets links
名前
Everettmus
marijuana dark web <a href="https://kingdom-darkmarket-online.com/ ">onion link reddit </a> https://kingdom-darkmarket-online.com/ - tor markets links
名前
Robertzeque
reddit darknet reviews <a href="https://kingdom-dark-market.com/ ">incognito market url </a> - best dark web marketplaces 2023
名前
Ronaldtic
best darknet market reddit <a href="https://heinekenmarketlink.com/ ">where to find onion links </a> https://heinekenmarketlink.com/ - darknet wiki link
名前
Wesleyenuse
darkfox market <a href="https://kingdomdrugsmarketplace.com/ ">adresse onion </a> https://kingdomdrugsmarket.com/ - tor2door darknet market
名前
ScottAduch
darknet market redit <a href="https://kingdomonlinedrugs.com/ ">darknet live markets </a> https://kingdomonlinedrugs.com/ - darknet search engine url
名前
Ronaldwrope
best websites dark web <a href="https://kingdomdarkweb.com/ ">buying credit cards on dark web </a> https://kingdomdarkweb.com/ - decentralized darknet market
名前
ElmerPralt
reddit darknet market guide <a href="https://darkmarketkingdom.com/ ">darknet credit card market </a> https://kingdomonion.com/ - alphabay market net
名前
Allenthuck
darknet bitcoin market <a href="https://heinekenexpressonion.com/ ">dark markets germany </a> https://heinekenexpressonion.com/ - dark markets indonesia
名前
DavidLeape
dark markets monaco <a href="https://heineken-express-onion.com/ ">buy ssn dob with bitcoin </a> https://heineken-express-onion.com/ - drug website dark web
名前
Andrewbem
darknet drugs price <a href="https://kingdom-drugs-market.com/ ">tor link list 2023 </a> https://kingdom-drugsonline.com/ - darknet market get pills
名前
Albertobut
phenethylamine drugs <a href="https://kingdom-darknet.com/ ">darknet market francais </a> https://kingdom-darkweb.com/ - current best darknet market
名前
DevinImMek
darknet markets reddit 2023 <a href="https://heinekenn-express.com/ ">dark markets singapore </a> https://heinekenmarketonlinee.com/ - how to get on darknet market
名前
EdwardDride
darknet markets with tobacco <a href="https://heinekennexpress.com/ ">dark web electronics </a> https://drheinekenexpress.com/ - links da deep web 2023
名前
ErnestHalry
dark market links <a href="https://heineken-marketplace.com/ ">how to access the black market </a> https://heinekenmarketplace24.com/ - updated darknet market links 2023
名前
CharlieZoose
black market drugs guns <a href="https://darkmarket-kingdom.com/ ">top darknet drug sites </a> https://darkmarket-kingdom.com/ - reliable darknet markets lsd
名前
HenryHap
site darknet fermГ© <a href="https://heinekendarkwebmarket.com/ ">how to get on darknet market </a> https://heinekendarkwebmarket.com/ - how to order from dark web
名前
WillisVow
black market websites credit cards <a href="https://kingdomdarkwebmarket.com/ ">darknet market and monero </a> https://kingdomdarkwebmarket.com/ - dark web website links
名前
WilliamUttep
top 10 dark web url <a href="https://kingdommarketurl.com/ ">best darknet markets </a> https://kingdomurl.com/ - cannabis dark web
名前
KevinClimi
darknet markets australia <a href="https://kingdommarketdarknet.com/ ">dark web vendors </a> https://kingdom-markett.com/ - darknet markets onion addresses
名前
Robertduelf
top darknet markets list <a href="https://kingdom-onlinedrugs.com/ ">top ten dark web sites </a> https://kingdom-drugs-online.com/ - onion websites for credit cards
名前
Jimmyrox
tor darknet market <a href="https://heineken-dark-market.com/ ">best darknet market for guns </a> https://heinekendarkmarketplace.com/ - link de hiden wiki
名前
RandyEduts
dark markets estonia <a href="https://heinekenmarketdarknet.com/ ">underground market place darknet </a> https://heinekendarknetmarket.com/ - Heineken Express link
名前
EdwardHal
dark market url <a href="https://heinekenmarket-online.com/ ">darknet dream market link </a> https://heinekenmarket-online.com/ - dark markets croatia
名前
EugeneGor
dark net market list <a href="https://heinekenmarket-darknet.com/ ">darknet markets norway 2023 </a> https://heinekenmarket-darknet.com/ - list of darknet markets reddit
名前
Williammulge
dark web live <a href="https://drkingdommarket.com/ ">best lsd darknet market </a> https://kingdommarketonlinee.com/ - archetyp market darknet
名前
RichardIcott
duckduckgo onion site <a href="https://heineken-darkwebmarket.com/ ">bitcoin dark web </a> https://heineken-darkwebmarket.com/ - search deep web engine
名前
Phillipget
darknet onion links drugs <a href="https://heineken-darkweb.com/ ">darknet drugs market </a> https://heineken-darknet.com/ - best darknet markets for vendors
名前
Arnoldinfop
french deep web link <a href="https://kingdommarketlink.com/ ">Heineken Express url </a> https://kingdommarketlink.com/ - live onion market
名前
HenryMaync
darknet bitcoin market <a href="https://kingdom-darkmarketplace.com/ ">dark market 2023 </a> https://kingdom-darkwebmarket.com/ - darknet market features
名前
Timothylen
working darknet market links <a href="https://kingdomdarkmarket.com/ ">versus project market link </a> https://kingdommarket-online.com/ - bohemia market link
名前
Davidinton
drug markets onion <a href="https://heinekendarkweb.com/ ">reddit darknet market noobs </a> https://heinekendarkweb.com/ - how to use the darknet markets
名前
Williamroubs
how to get on the dark web android <a href="https://kingdommarket-links.com/ ">deep dark web markets links </a> https://kingdommarket-darknet.com/ - darknet market alternatives
名前
JamesMop
dbol steroid pills <a href="https://heinekenmarket-links.com/ ">dark web markets </a> https://heinekenmarket-links.com/ - dark markets latvia
名前
JohnnyBiz
darknet market busts <a href="https://heinekenmarketurl.com/ ">reddit best darknet market </a> https://heinekenmarketurl.com/ - how to access the dark web on pc
名前
AndrewTelve
darknet market comparison <a href="https://darkweb-kingdom.com/ ">site darknet onion </a> https://darkweb-kingdom.com/ - orange sunshine lsd
名前
BrettUttep
adresse dark web <a href="https://heinekendarkmarketonline.com/ ">darknet market guide </a> https://heinekendarkmarketonline.com/ - 2023 darknet market
名前
EdwardOppow
alphabay darknet market <a href="https://dark-web-heineken.com/ ">dark web drugs bitcoin </a> https://darkmarket-heineken.com/ - best darknet gun market
名前
DanielNoubs
buy bitcoin for dark web <a href="https://darkmarketheineken.com/ ">underground card shop </a> https://darkmarketheineken.com/ - black market webshop
名前
Zacharywah

コメントを追加

CAPTCHA
この質問はあなたが人間の訪問者であるかどうかをテストし、自動化されたスパム送信を防ぐためのものです。
画像CAPTCHA
画像内に表示されている文字列を入力してください。