【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>

カテゴリー

コメント

darknet markets that take ethereum <a href="https://darkmarketheineken.com/ ">darknet markets urls </a> [url=https://darkmarketheineken.com/ ]safe list of darknet market links [/url]
名前
Zacharywah
best darknet market for lsd <a href="https://kingdomdarknet.com/ ">Cocorico Market darknet </a> https://kingdomdarkweb.com/ - new dark web links
名前
ElmerPralt
decentralized darknet market <a href="https://darkmarketkingdom.com/ ">dxm pills </a> https://darkmarketkingdom.com/ - guide to darknet markets
名前
Allenthuck
best darknet market links <a href="https://kingdom-darkweb.com/ ">biggest darknet market 2023 </a> https://kingdom-darkweb.com/ - Kingdom Market url
名前
DevinImMek
dark markets iceland <a href="https://heineken-darknet.com/ ">adress darknet </a> https://heineken-darkweb.com/ - what darknet markets are open
名前
Arnoldinfop
popular darknet markets <a href="https://kingdom-onion.com/ ">weed only darknet market </a> https://darkwebkingdom.com/ - dark web address list
名前
Everettmus
darkmarket list <a href="https://heinekenmarketdarknet.com/ ">dark markets bosnia </a> https://heinekenmarketdarknet.com/ - tor darknet
名前
EdwardHal
best darknet market now <a href="https://kingdom-onion-market.com/ ">xanax darknet reddit </a> https://kingdom-onion-market.com/ - dark web shop
名前
JamesGal
dark markets india <a href="https://kingdomdrugsonline.com/ ">versus link </a> https://kingdomonlinedrugs.com/ - Kingdom link
名前
Ronaldwrope
darkfox link <a href="https://heinekennexpress.com/ ">Kingdom Market link </a> https://heinekennexpress.com/ - dark markets serbia
名前
ErnestHalry
market links darknet <a href="https://kingdom-marketplace.com/ ">top ten dark web </a> https://kingdom-marketplace.com/ - asap market darknet
名前
Jeromesob
dark market sites <a href="https://heineken-onion.com/ ">access the dark web reddit </a> https://heineken-onion.com/ - drug market darknet
名前
DavidLeape
darknet prices <a href="https://heinekenmarket-darknet.com/ ">steroid market darknet </a> https://heinekenmarket-darknet.com/ - dark web shop
名前
Williammulge
best darknet market for psychedelics <a href="https://heineken-darkmarket.com/ ">grey market link </a> https://heineken-darkmarket.com/ - escrow dark web
名前
WillisVow
deep dark web <a href="https://kingdomdarknetdrugstore.com/ ">darknet dream market link </a> https://kingdomdarknetdrugstore.com/ - black market prescription drugs
名前
IgnacioVorge
what is a darknet drug market like <a href="https://kingdom-drugs-market.com/ ">dark market list </a> https://kingdom-drugsonline.com/ - tor market darknet
名前
Albertobut
bitcoin dark website <a href="https://heinekenmarketonlinee.com/ ">darknet market url list </a> https://heinekenmarketonlinee.com/ - onionhub
名前
EdwardDride
dark markets canada <a href="https://heineken-express-onion.com/ ">darknet drug markets </a> https://heineken-express-onion.com/ - darknet market deep dot web
名前
Andrewbem
how to get on darknet market <a href="https://kingdommarketdarknet.com/ ">darknet market </a> https://kingdommarketdarknet.com/ - onion websites for credit cards
名前
Robertduelf
versus project market <a href="https://darkfox-onion-darkmarket.com/ ">cypher darknet market </a> https://darkfoxdarkwebdrugstore.com/ - dark markets czech republic
名前
AlbertGlice
reddit darknet market deals <a href="https://darkmarket-kingdom.com/ ">dark market link </a> https://darkmarket-kingdom.com/ - darknet market for noobs
名前
HenryHap
darknet market dash <a href="https://kingdom-darkmarket.com/ ">grey market darknet link </a> https://kingdom-darkmarket.com/ - best darknet markets for vendors
名前
WilliamUttep
legit darknet markets <a href="https://heineken-darkmarketplace.com/ ">darknet market noobs bible </a> https://heineken-darkmarketplace.com/ - active darknet markets 2023
名前
Phillipget
darknet steroid markets <a href="https://heinekendarkmarket.com/ ">versus project market url </a> https://heinekendarkmarket.com/ - dark web payment methods
名前
EugeneGor
superlist darknet markets <a href="https://kingdom-drugs-online.com/ ">what is a darknet drug market like </a> https://kingdom-drugs-online.com/ - dark markets singapore
名前
Jimmyrox
onion link reddit <a href="https://kingdomdarkwebdrugstore.com/ ">top dark net markets </a> https://kingdom-darknet-drugstore.com/ - hidden financial services deep web
名前
DarrenMic
cypher url <a href="https://darkmarket-heineken.com/ ">dark web step by step </a> https://dark-web-heineken.com/ - dark net guide
名前
DanielNoubs
top darknet markets <a href="https://darkfoxdarknetdrugstore.com/ ">dark web fake money </a> https://darkfoxdarknetdrugstore.com/ - darknet market links safe
名前
Stanleymet
darkweb marketplace <a href="https://kingdom-darkweb-drugstore.com/ ">darknet reinkommen </a> https://heinekenmarketplacee.com/ - darknet market noobs guide
名前
MichaelJet
russian anonymous marketplace <a href="https://kingdom-darkmarketplace.com/ ">site darknet onion </a> https://kingdom-darkwebmarket.com/ - alphabay link reddit
名前
Timothylen
russian anonymous marketplace <a href="https://kingdommarket-online.com/ ">top darknet markets </a> https://kingdomdarkmarket.com/ - alphabay darknet market
名前
Davidinton
black market sites 2023 <a href="https://kingdom-online-drugs.com/ ">darknet credit card market </a> https://kingdomonionmarket.com/ - how to access darknet markets reddit
名前
BillyNut
tor2door market darknet <a href="https://darkweb-kingdom.com/ ">links the hidden wiki </a> https://darkweb-kingdom.com/ - how to use deep web on pc
名前
BrettUttep
darknet markets financial times <a href="https://heineken-dark-market.com/ ">cypher darknet market </a> https://heinekendarkmarketplace.com/ - dark web prepaid cards reddit
名前
RandyEduts
how to access dark net <a href="https://heinekenmarketlink.com/ ">what is escrow darknet markets </a> https://heinekenmarketlink.com/ - darknet market reviews
名前
Wesleyenuse
deep website search engine <a href="https://heinekenmarketplace24.com/ ">dnm market </a> https://heinekenmarketplace24.com/ - darknet links market
名前
CharlieZoose
dark markets norway <a href="https://kingdom-dark-market.com/ ">tor dark web </a> - dark market link
名前
Ronaldtic
bitcoin darknet drugs <a href="https://kingdom-darkmarket-online.com/ ">cheapest drugs on darknet </a> https://kingdomdarkmarketonline.com/ - versus link
名前
Robertzeque
versus project market url <a href="https://kingdomdrugsmarket.com/ ">superlist darknet markets </a> https://kingdomdrugsmarket.com/ - list of darknet markets 2023
名前
ScottAduch
darknet drugs reddit <a href="https://kingdomoniondarkweb.com/ ">darknet market </a> https://kingdomoniondarkweb.com/ - monero darknet market
名前
WesleyPex
guide to darknet markets <a href="https://heineken-darkweb.com/ ">dark markets 2023 </a> https://heineken-darkweb.com/ - tor search engine link
名前
Arnoldinfop
darknet telegram group <a href="https://heinekenmarketurl.com/ ">reliable darknet markets </a> https://heinekenurl.com/ - dark web hitmen
名前
AndrewTelve
dot onion websites <a href="https://heineken-darkmarket-online.com/ ">darknet wiki link </a> https://heinekendarkmarketonline.com/ - google black market
名前
EdwardOppow
deep web weed prices <a href="https://heinekenmarketdarknet.com/ ">onion tube porn </a> https://heinekenmarketdarknet.com/ - darknet prices
名前
EdwardHal
fake id dark web 2023 <a href="https://darkfox-onlinedrugs.com/ ">archetyp link </a> https://kingdommarketplacee.com/ - best card shops
名前
Baaket
darknet market iphone <a href="https://heinekendarkwebmarket.com/ ">Abacus Market darknet </a> https://heineken-darkmarket.com/ - dark web drugs nz
名前
WillisVow
darknet markets wax weed <a href="https://kingdomdarkweb.com/ ">list of online darknet market </a> https://kingdomdarkweb.com/ - darknet market links 2023 reddit
名前
ElmerPralt
buds express <a href="https://kingdomonion.com/ ">deep cp links </a> https://darkmarketkingdom.com/ - darknet markets still up
名前
Allenthuck
links da deep web 2023 <a href="https://kingdomdrugsonline.com/ ">dark markets latvia </a> https://kingdomdrugsonline.com/ - best dark web links
名前
Ronaldwrope
what is a darknet drug market like <a href="https://kingdom-onion-darkmarket.com/ ">darknet drugs malayisa </a> https://kingdom-onion-darkmarket.com/ - exploit market darknet
名前
JamesGal

コメントを追加

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