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

カテゴリー

コメント

escrow dark web <a href="https://darkfox-onlinedrugs.com/ ">black market url deep web </a> https://kingdommarketplacee.com/ - darknet guns market
名前
Baaket
what darknet market to use <a href="https://kingdommarketdarknet.com/ ">drugs on darknet </a> https://kingdommarketdarknet.com/ - grey market darknet link
名前
Robertduelf
darknet markets 2023 updated <a href="https://kingdom-drugsonline.com/ ">onion domain and kingdom </a> https://kingdom-drugs-market.com/ - versus market url
名前
Albertobut
steroid market darknet <a href="https://kingdom-onion-darkweb.com/ ">Cocorico url </a> https://kingdomdarknetdrugstore.com/ - deep web drug url
名前
IgnacioVorge
how to access dark web markets <a href="https://heinekenonion.com/ ">darknet market link updates </a> https://heinekenonion.com/ - dark web drugs
名前
Zacharywah
darknet markets most popular <a href="https://heinekenmarketonlinee.com/ ">deep web updated links </a> https://heinekenn-express.com/ - darknet telegram group
名前
EdwardDride
versus darknet market <a href="https://darkfoxonionmarket.com/ ">how to get on the dark web on laptop </a> https://darkfoxonionmarket.com/ - darknet drugs url
名前
Davidven
darknet black market <a href="https://kingdom-marketplace.com/ ">dark markets latvia </a> https://darkfox-onion-darkweb.com/ - reddit darknetmarket
名前
Jeromesob
tor2door market darknet <a href="https://heinekenexpressonion.com/ ">darkfox market darknet </a> https://heinekenexpressonion.com/ - darknet market reddit list
名前
DavidLeape
dark chart <a href="https://kingdom-darkmarket.com/ ">new darknet markets 2023 </a> https://kingdomdarkwebmarket.com/ - darknet online drugs
名前
WilliamUttep
legit darknet sites <a href="https://dark-web-kingdom.com/ ">grey market darknet link </a> https://dark-web-kingdom.com/ - uncensored deep web
名前
HenryHap
wiki sticks drugs <a href="https://kingdomdarkwebdrugstore.com/ ">market street darknet </a> https://kingdomdarkwebdrugstore.com/ - darknet search engine
名前
DarrenMic
darkfox darknet market <a href="https://kingdom-onlinedrugs.com/ ">dark markets san marino </a> https://kingdom-drugs-online.com/ - darkfox market darknet
名前
Jimmyrox
dark web buy credit cards <a href="https://heinekendarkmarket.com/ ">darknet drugs safe </a> https://heinekenmarket-online.com/ - darknet market iphone
名前
EugeneGor
incognito link <a href="https://darkwebheineken.com/ ">incognito darknet market </a> https://heineken-express-onion.com/ - dark web trading
名前
Andrewbem
steroid market darknet <a href="https://darkfox-onion-darkmarket.com/ ">darknet buy drugs </a> https://darkfoxdarkwebdrugstore.com/ - tor markets 2023
名前
AlbertGlice
wikipedia darknet market <a href="https://kingdommarketonlinee.com/ ">underground hackers black market </a> https://kingdommarketonlinee.com/ - black market websites 2023
名前
RichardIcott
darknet reddit market pills <a href="https://dark-web-heineken.com/ ">deep web drug prices </a> https://darkmarket-heineken.com/ - cypher market darknet
名前
DanielNoubs
darknet site <a href="https://heineken-dark-market.com/ ">Abacus link </a> https://heineken-dark-market.com/ - darknet market sites
名前
RandyEduts
darknet market oxycontin <a href="https://kingdom-darkweb-drugstore.com/ ">Heineken Express Market </a> https://heinekenmarketplacee.com/ - incognito link
名前
MichaelJet
which darknet markets accept zcash <a href="https://darkfoxdarknetdrugstore.com/ ">onion live links </a> https://darkfoxdarknetdrugstore.com/ - cvv black market
名前
Stanleymet
onion directory <a href="https://kingdommarket-online.com/ ">dream market darknet </a> https://kingdommarket-online.com/ - vice city link
名前
Davidinton
hidden marketplace <a href="https://kingdom-darkmarketplace.com/ ">buying things from darknet markets </a> https://kingdom-darkmarketplace.com/ - deep onion links
名前
Timothylen
deep web drug url <a href="https://darkweb-kingdom.com/ ">reddit darknet market 2023 </a> https://dark-market-kingdom.com/ - deep dark web markets links
名前
BrettUttep
reddit darknet markets links <a href="https://kingdom-online-drugs.com/ ">darknet markets </a> https://kingdom-online-drugs.com/ - dark markets luxembourg
名前
BillyNut
Heineken Express url <a href="https://heinekenmarketplace24.com/ ">best darknet market for lsd </a> https://heinekenmarketplace24.com/ - darknet markets that take ethereum
名前
CharlieZoose
list of darknet markets reddit <a href="https://heineken-darknet.com/ ">darknet markets financial times </a> https://heineken-darknet.com/ - darknet market search engine
名前
Arnoldinfop
drugs on the deep web <a href="https://kingdommarket-darknet.com/ ">how to buy bitcoin and use on dark web </a> https://kingdommarket-darknet.com/ - darknet adress
名前
JamesMop
best dark web links <a href="https://kingdommarketlink.com/ ">darknet drug trafficking </a> https://kingdommarketlink.com/ - how to get to darknet market safe
名前
HenryMaync
dark web drugs <a href="https://heinekendarkwebmarket.com/ ">bohemia url </a> https://heineken-darkmarket.com/ - cypher market
名前
WillisVow
darknet search <a href="https://kingdomurl.com/ ">dark web markets 2023 </a> https://kingdomurl.com/ - dark web shopping
名前
KevinClimi
tor2door link <a href="https://heinekenmarketdarknet.com/ ">dark web shopping </a> https://heinekenmarketdarknet.com/ - versus link
名前
EdwardHal
onion linkek <a href="https://heinekenmarket-url.com/ ">darknet links markets </a> https://heinekenmarketlink.com/ - darknet drug delivery
名前
Wesleyenuse
the darknet markets <a href="https://kingdom-darkmarket-online.com/ ">alphabay darknet market </a> https://kingdom-darkmarket-online.com/ - darkfox market url
名前
Robertzeque
hitman for hire dark web <a href="https://kingdomdarkmarketplace.com/ ">google black market </a> - darknet union
名前
Ronaldtic
ruonion <a href="https://kingdomoniondarkweb.com/ ">deep web links updated </a> https://kingdomoniondarkweb.com/ - hidden marketplace
名前
WesleyPex
darknet drug vendors <a href="https://kingdomdrugsmarket.com/ ">dark web sites xxx </a> https://kingdomdrugsmarket.com/ - darknet markets guide
名前
ScottAduch
dark markets norway <a href="https://heineken-markett.com/ ">darknet live stream </a> https://heineken-markett.com/ - dark markets luxembourg
名前
Williammulge
dark web search engines link <a href="https://kingdomdrugsonline.com/ ">dark markets hungary </a> https://kingdomdrugsonline.com/ - black market buy online
名前
Ronaldwrope
best websites dark web <a href="https://kingdom-onion-market.com/ ">best dark net markets </a> https://kingdom-onion-market.com/ - dark markets belarus
名前
JamesGal
darkmarkets <a href="https://heineken-darkmarketplace.com/ ">exploit market darknet </a> https://heineken-darkmarketplace.com/ - which darknet markets are still open
名前
Phillipget
black market webshop <a href="https://heinekenmarketurl.com/ ">deep web drug store </a> https://heinekenurl.com/ - best darknet market urs
名前
AndrewTelve
asap market url <a href="https://darkmarketkingdom.com/ ">what darknet markets are still open </a> https://kingdomonion.com/ - darknet drugs url
名前
Allenthuck
reddit darknet market 2023 <a href="https://kingdomdarkweb.com/ ">darknet sites drugs </a> https://kingdomdarknet.com/ - Abacus Market darknet
名前
ElmerPralt
darknet drugs reddit <a href="https://kingdom-darknet.com/ ">dark markets czech republic </a> https://kingdom-darkweb.com/ - archetyp link
名前
DevinImMek
darknet markets 2023 reddit <a href="https://kingdom-onion.com/ ">how to buy drugs on darknet </a> https://darkwebkingdom.com/ - darknet illicit drugs
名前
Everettmus
dark web links market <a href="https://kingdommarketdarknet.com/ ">black market illegal drugs </a> https://kingdom-markett.com/ - dark markets monaco
名前
Robertduelf
what darknet market to use <a href="https://drheinekenexpress.com/ ">darknet drug markets reddit </a> [url=https://heinekennexpress.com/ ]tor market links [/url]
名前
ErnestHalry
versus market link <a href="https://kingdomdarknetdrugstore.com/ ">Kingdom Market darknet </a> https://kingdom-onion-darkweb.com/ - how to browse the dark web reddit
名前
IgnacioVorge
what darknet markets are available <a href="https://kingdom-drugs-market.com/ ">best darknet markets reddit </a> https://kingdom-drugsonline.com/ - deep net access
名前
Albertobut

コメントを追加

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