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

カテゴリー

コメント

tor dark web <a href="https://kingdom-drugsonline.com/ ">dark web login guide </a> https://kingdom-drugsonline.com/ - carding deep web links
名前
Albertobut
darkweb sites reddit <a href="https://heinekenexpressonion.com/ ">active darknetmarkets </a> https://heineken-onion.com/ - dark web markets reddit
名前
DavidLeape
darknet market forum <a href="https://kingdom-markett.com/ ">the dark market </a> https://kingdommarketdarknet.com/ - black market prices for drugs
名前
Robertduelf
vice city market <a href="https://kingdommarketurl.com/ ">best onion sites 2023 </a> https://kingdomurl.com/ - dark markets guyana
名前
KevinClimi
cheap darknet websites dor drugs <a href="https://heineken-express-onion.com/ ">darknet search engine url </a> https://darkwebheineken.com/ - best darknet market australia
名前
Andrewbem
darknet black market url <a href="https://kingdom-darkmarket.com/ ">black market website legit </a> https://kingdomdarkwebmarket.com/ - legit darknet sites
名前
WilliamUttep
dark markets venezuela <a href="https://heinekendarknetmarket.com/ ">darknet market carding </a> https://heinekenmarketdarknet.com/ - bitcoin cash darknet markets
名前
EdwardHal
darknet markets still up <a href="https://darkmarket-kingdom.com/ ">darknet markets fake id </a> https://dark-web-kingdom.com/ - biggest darknet markets 2023
名前
HenryHap
buying credit cards on dark web <a href="https://heinekendarkwebmarket.com/ ">darknet drug vendor that takes paypal </a> https://heinekendarkwebmarket.com/ - dark markets romania
名前
WillisVow
dark markets macedonia <a href="https://heineken-markett.com/ ">dn market </a> https://heineken-markett.com/ - dark markets malta
名前
Williammulge
legit onion sites <a href="https://kingdom-drugs-online.com/ ">darknet market status </a> https://kingdom-drugs-online.com/ - biggest darknet markets
名前
Jimmyrox
drug markets onion <a href="https://kingdommarketonlinee.com/ ">tor market links 2023 </a> https://drkingdommarket.com/ - darknet market prices
名前
RichardIcott
asap market link <a href="https://heinekendarkmarketplace.com/ ">dark web cvv </a> https://heineken-dark-market.com/ - dream market darknet link
名前
RandyEduts
where to find onion links <a href="https://heinekendarkmarket.com/ ">dark markets austria </a> https://heinekendarkmarket.com/ - active darknet market urls
名前
EugeneGor
deep dot web markets <a href="https://heineken-darkmarketplace.com/ ">best darknet market for heroin </a> https://heineken-darkmarketplace.com/ - online black market electronics
名前
Phillipget
deep web cc shop <a href="https://kingdommarket-online.com/ ">Heineken Express Market </a> https://kingdomdarkmarket.com/ - buy bank accounts darknet
名前
Davidinton
onion link reddit <a href="https://kingdommarket-links.com/ ">best darknet market for psychedelics </a> https://kingdommarket-darknet.com/ - versus project link
名前
JamesMop
how to get to darknet market <a href="https://heineken-darknet.com/ ">biggest darknet markets </a> https://heineken-darknet.com/ - dark web xanax
名前
Arnoldinfop
black market website legit <a href="https://heinekenmarket-links.com/ ">reddit best darknet markets </a> https://heinekenmarket-link.com/ - darknet drugs price
名前
JohnnyBiz
most popular darknet market <a href="https://kingdom-darkmarketplace.com/ ">archetyp market link </a> https://kingdom-darkmarketplace.com/ - the onion directory
名前
Timothylen
online black market uk <a href="https://heinekendarknet.com/ ">black market online website </a> https://heinekendarkweb.com/ - Heineken Express darknet Market
名前
Williamroubs
drugs dark web reddit <a href="https://heinekenurl.com/ ">deep market </a> https://heinekenurl.com/ - underground website to buy drugs
名前
AndrewTelve
phenylethylamine <a href="https://darkmarketheineken.com/ ">best dark web marketplaces 2023 </a> https://heinekenonion.com/ - active darknet market urls
名前
Zacharywah
darkfox market url <a href="https://darkweb-kingdom.com/ ">reddit darknetmarket </a> https://darkweb-kingdom.com/ - darknet market deep dot web
名前
BrettUttep
dark web drugs nz <a href="https://kingdomdarkmarketplace.com/ ">tor marketplace </a> - darknet market iphone
名前
Ronaldtic
dark web links reddit <a href="https://kingdom-onion.com/ ">deep web drugs reddit </a> https://darkwebkingdom.com/ - step by step dark web
名前
Everettmus
dumps shop <a href="https://kingdomdarkmarketonline.com/ ">darknet drugs dublin </a> https://kingdomdarkmarketonline.com/ - what darknet markets sell fentanyl
名前
Robertzeque
duckduckgo dark web search <a href="https://heinekenmarketlink.com/ ">archetyp market link </a> https://heinekenmarket-url.com/ - darknet market noobs
名前
Wesleyenuse
mdm love drug <a href="https://heineken-onion.com/ ">darknet adressen </a> https://heinekenexpressonion.com/ - versus darknet market
名前
DavidLeape
best deep web markets <a href="https://kingdomdrugsmarket.com/ ">dark markets korea </a> https://kingdomdrugsmarket.com/ - dark web hitmen
名前
ScottAduch
dark web market links <a href="https://kingdom-markett.com/ ">back market legit </a> https://kingdommarketdarknet.com/ - best black market websites
名前
Robertduelf
incognito market darknet <a href="https://kingdom-darkweb.com/ ">superman pills mg </a> https://kingdom-darknet.com/ - xanax darknet reddit
名前
DevinImMek
deep web search engine 2023 <a href="https://kingdomurl.com/ ">dark web drugs nz </a> https://kingdomurl.com/ - deep web search engine url
名前
KevinClimi
onion market <a href="https://heinekenn-express.com/ ">darkfox link </a> https://heinekenmarketonlinee.com/ - darknet drugs links
名前
EdwardDride
links da deep web 2023 <a href="https://heinekennexpress.com/ ">darknet markets norway 2023 </a> https://drheinekenexpress.com/ - black market websites tor
名前
ErnestHalry
alphabay link <a href="https://kingdomdrugsonline.com/ ">drugs on darknet </a> https://kingdomonlinedrugs.com/ - bohemia market link
名前
Ronaldwrope
buying darknet drugs <a href="https://darkmarketkingdom.com/ ">superman pills mg </a> https://darkmarketkingdom.com/ - deep web marketplaces reddit
名前
Allenthuck
outlaw darknet market url <a href="https://heineken-marketplace.com/ ">duckduckgo dark web search </a> https://heineken-marketplace.com/ - tor link search engine
名前
CharlieZoose
bitcoin market on darknet tor <a href="https://heineken-express-onion.com/ ">darknet guide </a> https://darkwebheineken.com/ - bohemia darknet market
名前
Andrewbem
brick market <a href="https://kingdom-drugs-market.com/ ">vice city market link </a> https://kingdom-drugs-market.com/ - dark web weed
名前
Albertobut
dark web vendors <a href="https://kingdomdarkwebmarket.com/ ">best darknet drug market 2023 </a> https://kingdom-darkmarket.com/ - phenylethylamine
名前
WilliamUttep
darknet drugs reddit <a href="https://heinekendarknetmarket.com/ ">darknet market reddit 2023 </a> https://heinekenmarketdarknet.com/ - darknet drugs dublin
名前
EdwardHal
what darknet markets are available <a href="https://heinekenmarket-darknet.com/ ">biggest darknet markets 2023 </a> https://heinekenmarket-darknet.com/ - best darknet markets uk
名前
Williammulge
black market online website <a href="https://drkingdommarket.com/ ">darknet online drugs </a> https://drkingdommarket.com/ - dark markets bulgaria
名前
RichardIcott
darkfox darknet market <a href="https://heineken-darkmarket.com/ ">buying credit cards on dark web </a> https://heineken-darkmarket.com/ - how to pay with bitcoin on dark web
名前
WillisVow
reliable darknet markets reddit <a href="https://kingdom-drugs-online.com/ ">tor search onion link </a> https://kingdom-drugs-online.com/ - dark web link
名前
Jimmyrox
bitcoin dark website <a href="https://heinekendarkmarketplace.com/ ">underground market online </a> https://heineken-dark-market.com/ - darknet market status
名前
RandyEduts
dark markets belgium <a href="https://heinekendarkmarket.com/ ">ordering drugs on dark web </a> https://heinekenmarket-online.com/ - drug markets dark web
名前
EugeneGor
how to get to the black market online <a href="https://kingdommarket-darknet.com/ ">superlist darknet markets </a> https://kingdommarket-links.com/ - underground market place darknet
名前
JamesMop
r darknet market <a href="https://kingdomdarkmarket.com/ ">popular darknet markets </a> https://kingdommarket-online.com/ - darkmarket
名前
Davidinton

コメントを追加

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