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

カテゴリー

コメント

bohemia market <a href="https://kingdom-darknet-drugstore.com/ ">shop on the dark web </a> https://kingdomdarkwebdrugstore.com/ - how to access darknet market
名前
DarrenMic
dark web directory <a href="https://darkmarketheineken.com/ ">black market websites 2023 </a> https://heinekenonion.com/ - history of darknet markets
名前
Zacharywah
dark web drug markets <a href="https://darkfoxonlinedrugs.com/ ">popular dark websites </a> https://darkfoxonionmarket.com/ - how to use darknet markets
名前
Davidven
Kingdom Market darknet <a href="https://heinekendarkmarket.com/ ">tor darknet market address </a> https://heinekenmarket-online.com/ - archetyp market url
名前
EugeneGor
darknet sites <a href="https://heinekendarkmarketplace.com/ ">new alphabay darknet market </a> https://heinekendarkmarketplace.com/ - dark web in spanish
名前
RandyEduts
online black market uk <a href="https://heinekenmarketplacee.com/ ">black market illegal drugs </a> https://heinekenmarketplacee.com/ - berlin telegram group drugs
名前
MichaelJet
online black market uk <a href="https://kingdom-marketplace.com/ ">buds express </a> https://darkfox-onion-darkweb.com/ - legit darknet sites
名前
Jeromesob
darknet market ddos <a href="https://heineken-onion.com/ ">darknet drugs malayisa </a> https://heineken-onion.com/ - the best onion sites
名前
DavidLeape
back market legit <a href="https://heineken-express-onion.com/ ">dream market darknet url </a> https://darkwebheineken.com/ - dark markets bosnia
名前
Andrewbem
darknet market features <a href="https://heineken-darkweb.com/ ">tor best websites </a> https://heineken-darknet.com/ - dark markets canada
名前
Arnoldinfop
darknet websites wiki <a href="https://darkfox-onion-darkmarket.com/ ">dark web address list </a> https://darkfox-onion-darkmarket.com/ - best darknet market for weed
名前
AlbertGlice
what is the best darknet market <a href="https://heineken-marketplace.com/ ">good dark web search engines </a> https://heinekenmarketplace24.com/ - dark web markets reddit
名前
CharlieZoose
fake id onion <a href="https://heineken-darkmarket.com/ ">current darknet markets reddit </a> https://heinekendarkwebmarket.com/ - tor market
名前
WillisVow
darknet sites url <a href="https://kingdomdarkmarket.com/ ">darknet markets availability </a> https://kingdommarket-online.com/ - access the black market
名前
Davidinton
duckduckgo onion site <a href="https://kingdom-darkmarketplace.com/ ">darknet market arrests </a> https://kingdom-darkmarketplace.com/ - top darknet markets 2023
名前
Timothylen
reddit darknet market guide <a href="https://dark-web-heineken.com/ ">archetyp market link </a> https://dark-web-heineken.com/ - bohemia market
名前
DanielNoubs
dark market url <a href="https://kingdom-online-drugs.com/ ">darkmarket </a> https://kingdom-online-drugs.com/ - cp onion
名前
BillyNut
Heineken Express url <a href="https://dark-market-kingdom.com/ ">darknet onion markets </a> https://dark-market-kingdom.com/ - legit darknet markets
名前
BrettUttep
dark web link <a href="https://heinekendarknetmarket.com/ ">how to browse the dark web reddit </a> https://heinekendarknetmarket.com/ - reddit darknet market noobs
名前
EdwardHal
versus project darknet market <a href="https://heineken-darkwebmarket.com/ ">cp links dark web </a> https://heineken-darkmarketplace.com/ - active darknet markets 2023
名前
Phillipget
dark net market list reddit <a href="https://darkfoxdarknetdrugstore.com/ ">online black market electronics </a> https://darkfoxdarknetdrugstore.com/ - incognito market link
名前
Stanleymet
darkmarket url <a href="https://heinekenmarket-darknet.com/ ">best mdma vendor darknet market reddit </a> https://heineken-markett.com/ - dark websites reddit
名前
Williammulge
how to buy bitcoin and use on dark web <a href="https://kingdom-darkmarket-online.com/ ">darknet search </a> https://kingdom-darkmarket-online.com/ - safe darknet markets
名前
Robertzeque
tor2door link <a href="https://kingdomdarkmarketplace.com/ ">darknet market ddos </a> - dark markets australia
名前
Ronaldtic
reliable darknet markets reddit <a href="https://heinekenmarket-url.com/ ">alphabay darknet market </a> https://heinekenmarketlink.com/ - deep web addresses onion
名前
Wesleyenuse
dark markets norway <a href="https://kingdomdrugsmarketplace.com/ ">darknet in person drug sales </a> https://kingdomdrugsmarketplace.com/ - dark markets slovenia
名前
ScottAduch
how to buy bitcoin and use on dark web <a href="https://kingdomoniondarkmarket.com/ ">dark web onion markets </a> https://kingdomoniondarkweb.com/ - legit darknet markets 2023
名前
WesleyPex
dark markets indonesia <a href="https://kingdom-onion-market.com/ ">guns dark market </a> https://kingdom-onion-market.com/ - australian darknet markets
名前
JamesGal
darknet markets with tobacco <a href="https://kingdomdrugsonline.com/ ">dream market darknet url </a> https://kingdomdrugsonline.com/ - how to dark web reddit
名前
Ronaldwrope
underground dumps shop <a href="https://kingdomonion.com/ ">reddit best darknet markets </a> https://darkmarketkingdom.com/ - Cocorico link
名前
Allenthuck
deep web market links reddit <a href="https://kingdomdarkweb.com/ ">blackweb darknet market </a> https://kingdomdarkweb.com/ - vice city market link
名前
ElmerPralt
tor market links <a href="https://heinekenmarketurl.com/ ">darkmarket list </a> https://heinekenmarketurl.com/ - best card shops
名前
AndrewTelve
tor2door market link <a href="https://kingdom-darkweb.com/ ">active darknet market urls </a> https://kingdom-darknet.com/ - Cocorico Market link
名前
DevinImMek
underground market online <a href="https://kingdom-drugsonline.com/ ">onion darknet market </a> https://kingdom-drugs-market.com/ - naked lady ecstasy pill
名前
Albertobut
Heineken Express darknet <a href="https://kingdom-onion-darkweb.com/ ">dark markets indonesia </a> https://kingdom-onion-darkweb.com/ - buy bitcoin for dark web
名前
IgnacioVorge
dark markets ireland <a href="https://kingdom-onion.com/ ">dark web drug markets </a> https://darkwebkingdom.com/ - site onion liste
名前
Everettmus
dark markets san marino <a href="https://drheinekenexpress.com/ ">tor dark web </a> https://heinekennexpress.com/ - darknet markets wax weed
名前
ErnestHalry
darknet market prices <a href="https://heinekenmarketonlinee.com/ ">tramadol dark web </a> https://heinekenmarketonlinee.com/ - drug markets onion
名前
EdwardDride
how to anonymously use darknet markets <a href="https://heinekendarkmarketplace.com/ ">deep dot web replacement </a> https://heineken-dark-market.com/ - Cocorico link
名前
RandyEduts
best darknet drug sites <a href="https://kingdom-darkmarket.com/ ">alphabay market </a> https://kingdomdarkwebmarket.com/ - darknet markets most popular
名前
WilliamUttep
darknet markets 2023 reddit <a href="https://dark-web-kingdom.com/ ">Cocorico Market link </a> https://darkmarket-kingdom.com/ - darknet black market list
名前
HenryHap
current darknet markets <a href="https://kingdomdarkwebdrugstore.com/ ">darknet market buying mdma usa </a> https://kingdom-darknet-drugstore.com/ - we amsterdam
名前
DarrenMic
escrow dark web <a href="https://kingdom-drugs-online.com/ ">Abacus darknet Market </a> https://kingdom-drugs-online.com/ - dark web drug marketplace
名前
Jimmyrox
darknet search engine url <a href="https://heinekendarkmarketonline.com/ ">dark web cheap electronics </a> https://heineken-darkmarket-online.com/ - tor2door market
名前
EdwardOppow
black market net <a href="https://heinekendarkmarket.com/ ">shop ccs carding </a> https://heinekenmarket-online.com/ - darknet gun market
名前
EugeneGor
dark markets luxembourg <a href="https://darkfox-onlinedrugs.com/ ">darknet drugs sales </a> https://darkfox-onlinedrugs.com/ - darknet market noobs bible
名前
Baaket
dark markets estonia <a href="https://kingdom-darkweb-drugstore.com/ ">darknet список сайтов </a> https://heinekenmarketplacee.com/ - dark markets usa
名前
MichaelJet
dark web onion markets <a href="https://darkmarketheineken.com/ ">dark markets uruguay </a> https://darkmarketheineken.com/ - how to access the black market
名前
Zacharywah
legit darknet markets 2023 <a href="https://darkfoxonionmarket.com/ ">dark markets romania </a> https://darkfoxonlinedrugs.com/ - dark markets bosnia
名前
Davidven
dark websites <a href="https://heineken-darkweb.com/ ">darknet markets onion addresses </a> https://heineken-darkweb.com/ - onion tube porn
名前
Arnoldinfop

コメントを追加

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