【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 websites <a href="https://dark-market-kingdom.com/ ">versus market darknet </a> https://dark-market-kingdom.com/ - tor link search engine
名前
BrettUttep
how to get to darknet market safe <a href="https://heinekenurl.com/ ">tor2door market </a> https://heinekenmarketurl.com/ - reddit darknetmarket
名前
AndrewTelve
black market net <a href="https://heineken-markett.com/ ">best website to buy cc </a> https://heinekenmarket-darknet.com/ - bitcoin darknet drugs
名前
Williammulge
alphabay market <a href="https://kingdommarketlink.com/ ">dark web markets reddit 2023 </a> https://kingdommarket-url.com/ - dark markets
名前
HenryMaync
active darknet markets <a href="https://heineken-express-onion.com/ ">onion dark web list </a> https://darkwebheineken.com/ - step by step dark web
名前
Andrewbem
deep web updated links <a href="https://kingdommarket-links.com/ ">dark markets luxembourg </a> https://kingdommarket-darknet.com/ - vice city market link
名前
JamesMop
darknet market steroids <a href="https://kingdom-onion.com/ ">Abacus link </a> https://darkwebkingdom.com/ - dark markets south korea
名前
Everettmus
dxm pills <a href="https://kingdomdarkmarketplace.com/ ">dark web store </a> - best website to buy cc
名前
Ronaldtic
dark markets croatia <a href="https://kingdomdarkmarketonline.com/ ">reddit darknet market noobs bible </a> https://kingdomdarkmarketonline.com/ - darknet market vendors search
名前
Robertzeque
reddit darknet market noobs bible <a href="https://kingdomdrugsmarket.com/ ">Cocorico Market </a> https://kingdomdrugsmarketplace.com/ - darknet wiki link
名前
ScottAduch
darknet link drugs <a href="https://heinekenmarket-url.com/ ">versus darknet market </a> https://heinekenmarketlink.com/ - darknet markets ranked 2023
名前
Wesleyenuse
vice city link <a href="https://kingdomdrugsonline.com/ ">versus market link </a> https://kingdomonlinedrugs.com/ - weed only darknet market
名前
Ronaldwrope
darknet market wikia <a href="https://heinekenmarket-links.com/ ">dark web hitman </a> https://heinekenmarket-link.com/ - dark web markets
名前
JohnnyBiz
best deep web markets <a href="https://kingdomdarknet.com/ ">deep web links 2023 reddit </a> https://kingdomdarkweb.com/ - Abacus Market darknet
名前
ElmerPralt
biggest darknet market <a href="https://kingdomonion.com/ ">darknet markets up </a> https://kingdomonion.com/ - dark web markets
名前
Allenthuck
darknet market package <a href="https://kingdom-darkweb.com/ ">market deep web 2023 </a> https://kingdom-darkweb.com/ - dark markets japan
名前
DevinImMek
tor2door market darknet <a href="https://kingdom-drugs-market.com/ ">new alphabay darknet market </a> https://kingdom-drugs-market.com/ - darknet drugs reddit
名前
Albertobut
deep net links <a href="https://drheinekenexpress.com/ ">legit darknet markets 2023 </a> https://drheinekenexpress.com/ - deep web directory onion
名前
ErnestHalry
illegal black market <a href="https://heinekenmarketonlinee.com/ ">sichere darknet markets 2023 </a> https://heinekenn-express.com/ - darknet markets lsd-25 2023
名前
EdwardDride
current darknet market list <a href="https://darkmarket-kingdom.com/ ">darknet markets still open </a> https://darkmarket-kingdom.com/ - lsd drug wiki
名前
HenryHap
dark markets paraguay <a href="https://heineken-darkmarket.com/ ">biggest darknet market 2023 </a> https://heineken-darkmarket.com/ - dark markets poland
名前
WillisVow
hire an assassin dark web <a href="https://kingdom-darkmarket.com/ ">onion sex shop </a> https://kingdomdarkwebmarket.com/ - darknet markets with tobacco
名前
WilliamUttep
tma drug <a href="https://kingdom-onlinedrugs.com/ ">blue lady e pill </a> https://kingdom-drugs-online.com/ - deep web shopping site
名前
Jimmyrox
archetyp market url <a href="https://heinekendarkmarketplace.com/ ">the darknet markets </a> https://heinekendarkmarketplace.com/ - top darknet markets 2023
名前
RandyEduts
dark markets greece <a href="https://heinekenmarket-online.com/ ">dark market list </a> https://heinekenmarket-online.com/ - onion directory list
名前
EugeneGor
dxm pills <a href="https://heineken-darkmarketplace.com/ ">what darknet markets are up </a> https://heineken-darkmarketplace.com/ - marijuana dark web
名前
Phillipget
shop online without cvv code <a href="https://heinekenmarketplace24.com/ ">naked lady ecstasy pill </a> https://heinekenmarketplace24.com/ - reddit darknet market noobs
名前
CharlieZoose
tor market links 2023 <a href="https://heineken-darkweb.com/ ">decentralized darknet market </a> https://heineken-darkweb.com/ - darknet steroid markets
名前
Arnoldinfop
darknet market credit cards <a href="https://heinekendarkmarketonline.com/ ">darknet market and monero </a> https://heinekendarkmarketonline.com/ - darknet markets up
名前
EdwardOppow
darknetlive <a href="https://kingdomurl.com/ ">dark web login guide </a> https://kingdomurl.com/ - deep web cc shop
名前
KevinClimi
deep web links reddit 2023 <a href="https://kingdom-markett.com/ ">darknet drugs reddit </a> https://kingdommarketdarknet.com/ - dark markets bulgaria
名前
Robertduelf
deep web cc dumps <a href="https://drkingdommarket.com/ ">buy drugs on darknet </a> https://drkingdommarket.com/ - buy drugs darknet
名前
RichardIcott
drugs on deep web <a href="https://heinekenmarketdarknet.com/ ">darknet markets address </a> https://heinekendarknetmarket.com/ - best darknet market for weed 2023
名前
EdwardHal
dread onion <a href="https://dark-web-heineken.com/ ">black market website names </a> https://dark-web-heineken.com/ - darknet market features
名前
DanielNoubs
dark web xanax <a href="https://darkmarketheineken.com/ ">tor dark web </a> https://darkmarketheineken.com/ - dark markets thailand
名前
Zacharywah
darknet serious market <a href="https://heineken-markett.com/ ">fake id dark web 2023 </a> https://heineken-markett.com/ - credit card black market websites
名前
Williammulge
darknet markets urls <a href="https://heinekendarknet.com/ ">escrow dark web </a> https://heinekendarknet.com/ - black market url deep web
名前
Williamroubs
best darknet market for lsd <a href="https://kingdom-darkwebmarket.com/ ">darknet drugs shipping </a> https://kingdom-darkmarketplace.com/ - what darknet markets still work
名前
Timothylen
dark markets united kingdom <a href="https://kingdomdarkmarket.com/ ">gray market place </a> https://kingdommarket-online.com/ - darknet in person drug sales
名前
Davidinton
darknet market lists <a href="https://darkweb-kingdom.com/ ">orange sunshine lsd </a> https://darkweb-kingdom.com/ - working darknet markets 2023
名前
BrettUttep
darknet market noobs bible <a href="https://kingdommarketlink.com/ ">deep dot web markets </a> https://kingdommarket-url.com/ - darknet market reddit list
名前
HenryMaync
guns dark market <a href="https://heinekenmarketurl.com/ ">grey market link </a> https://heinekenmarketurl.com/ - tor market url
名前
AndrewTelve
what are darknet drug markets <a href="https://kingdommarket-darknet.com/ ">deep sea darknet market </a> https://kingdommarket-links.com/ - live dark web
名前
JamesMop
dark web shop <a href="https://heinekenexpressonion.com/ ">dark web links market </a> https://heinekenexpressonion.com/ - reddit darknet market deals
名前
DavidLeape
dark markets iceland <a href="https://darkwebheineken.com/ ">dark web buy credit cards </a> https://heineken-express-onion.com/ - bitcoin darknet markets
名前
Andrewbem
what darknet market to use now <a href="https://darkwebkingdom.com/ ">drugs on deep web </a> https://kingdom-onion.com/ - best current darknet market
名前
Everettmus
ethereum darknet markets <a href="https://kingdom-dark-market.com/ ">darkweb marketplace </a> - darknet websites
名前
Ronaldtic
onion linkek <a href="https://kingdomdarkmarketonline.com/ ">darknet markets list 2023 </a> https://kingdomdarkmarketonline.com/ - darknet search engine url
名前
Robertzeque
dark markets belarus <a href="https://heinekenmarketlink.com/ ">fake id onion </a> https://heinekenmarket-url.com/ - dark markets montenegro
名前
Wesleyenuse
pill with crown on it <a href="https://kingdomdrugsmarket.com/ ">darknet market links safe </a> https://kingdomdrugsmarket.com/ - darknet market alternatives
名前
ScottAduch

コメントを追加

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