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

カテゴリー

コメント

top dark net markets <a href="https://darkwebheineken.com/ ">alphabay market net </a> https://darkwebheineken.com/ - buying drugs off darknet
名前
Andrewbem
best dark web links <a href="https://heinekenonion.com/ ">carding deep web links </a> https://darkmarketheineken.com/ - darknet drugs sales
名前
Zacharywah
darknet market superlist <a href="https://kingdommarket-darknet.com/ ">darknet market carding </a> https://kingdommarket-links.com/ - how to buy from darknet markets
名前
JamesMop
darknet market adressen <a href="https://heinekendarkweb.com/ ">onion seiten </a> https://heinekendarknet.com/ - the darknet markets
名前
Williamroubs
search darknet market <a href="https://heineken-marketplace.com/ ">darknet market drug prices </a> https://heineken-marketplace.com/ - onion seiten
名前
CharlieZoose
how to access the black market <a href="https://dark-market-kingdom.com/ ">how to get access to darknet </a> https://dark-market-kingdom.com/ - best dark web counterfeit money
名前
BrettUttep
buying from darknet market with electrum <a href="https://heineken-darkmarket.com/ ">darknet market 2023 reddit </a> https://heinekendarkwebmarket.com/ - black market sites 2023
名前
WillisVow
deep web search engine url <a href="https://kingdom-darknet.com/ ">darknet drug vendors </a> https://kingdom-darknet.com/ - onion deep web wiki
名前
DevinImMek
black market sites 2023 <a href="https://kingdommarket-online.com/ ">best fraud market darknet </a> https://kingdomdarkmarket.com/ - the armory tor url
名前
Davidinton
black market access <a href="https://kingdommarketdarknet.com/ ">florida darknet markets </a> https://kingdom-markett.com/ - how to get on the dark web on laptop
名前
Robertduelf
where to find darknet market links <a href="https://kingdommarketurl.com/ ">the darknet drugs </a> https://kingdommarketurl.com/ - dark web sites drugs
名前
KevinClimi
darknet market listing <a href="https://darkmarketkingdom.com/ ">live onion market </a> https://kingdomonion.com/ - dark web steroids
名前
Allenthuck
deep web deb <a href="https://kingdomdrugsmarketplace.com/ ">dark web trading </a> https://kingdomdrugsmarket.com/ - dark net market list reddit
名前
ScottAduch
darknet markets ranked 2023 <a href="https://heinekendarknetmarket.com/ ">list of darknet markets reddit </a> https://heinekenmarketdarknet.com/ - best darknet market for weed 2023
名前
EdwardHal
dark markets russia <a href="https://kingdom-dark-market.com/ ">russian anonymous marketplace </a> - underground website to buy drugs
名前
Ronaldtic
onion seiten <a href="https://kingdomdrugsonline.com/ ">adresse dark web </a> https://kingdomdrugsonline.com/ - dark market onion
名前
Ronaldwrope
top ten dark web sites <a href="https://heineken-markett.com/ ">dark markets montenegro </a> https://heineken-markett.com/ - tor onion search
名前
Williammulge
versus project market darknet <a href="https://kingdom-drugsonline.com/ ">legit darknet markets </a> https://kingdom-drugsonline.com/ - buying from darknet market with electrum
名前
Albertobut
top darknet market now <a href="https://darkmarketheineken.com/ ">incognito market link </a> https://heinekenonion.com/ - reddit working darknet markets
名前
Zacharywah
darknet links 2023 drugs <a href="https://dark-web-kingdom.com/ ">can you buy drugs on darknet </a> https://darkmarket-kingdom.com/ - escrow market darknet
名前
HenryHap
darknet markets may 2023 <a href="https://kingdommarketonlinee.com/ ">darknet market adderall prices </a> https://drkingdommarket.com/ - deep web weed prices
名前
RichardIcott
darknet live stream <a href="https://heinekenmarket-link.com/ ">darknet market carding </a> https://heinekenmarket-link.com/ - dark web sites links
名前
JohnnyBiz
darknet list <a href="https://kingdom-drugs-online.com/ ">darknet drug prices uk </a> https://kingdom-onlinedrugs.com/ - reddit darknet markets uk
名前
Jimmyrox
darknet markets noob <a href="https://kingdom-onion.com/ ">vice city link </a> https://kingdom-onion.com/ - crypto market darknet
名前
Everettmus
darknet market drug prices <a href="https://kingdom-darkwebmarket.com/ ">darknet markets fake id </a> https://kingdom-darkmarketplace.com/ - dark markets france
名前
Timothylen
deep deep web links <a href="https://kingdommarket-links.com/ ">versus market </a> https://kingdommarket-darknet.com/ - dark markets bosnia
名前
JamesMop
darknet market bible <a href="https://kingdommarketdarknet.com/ ">brick market </a> https://kingdom-markett.com/ - darknet drugs links
名前
Robertduelf
best fraud market darknet <a href="https://kingdommarketurl.com/ ">darknet links markets </a> https://kingdomurl.com/ - drugs on deep web
名前
KevinClimi
darknet drugs dublin <a href="https://kingdomdarkmarketplace.com/ ">ketamine darknet market </a> - how to get to darknet market safe
名前
Ronaldtic
incognito darknet market <a href="https://heinekenmarketplace24.com/ ">how to buy from darknet markets </a> https://heinekenmarketplace24.com/ - Heineken Express link
名前
CharlieZoose
Heineken Express link <a href="https://darkweb-kingdom.com/ ">darknet markets still open </a> https://darkweb-kingdom.com/ - best fraud market darknet
名前
BrettUttep
darknet market xanax <a href="https://drkingdommarket.com/ ">darknet market script </a> https://drkingdommarket.com/ - deep net links
名前
RichardIcott
dark markets thailand <a href="https://kingdomonion.com/ ">ketamine darknet market </a> https://kingdomonion.com/ - buying drugs online on openbazaar
名前
Allenthuck
darknet drug markets <a href="https://kingdomdrugsmarketplace.com/ ">darknet drug prices </a> https://kingdomdrugsmarketplace.com/ - tor darknet market
名前
ScottAduch
how to buy bitcoin for the dark web <a href="https://heinekendarknetmarket.com/ ">what are darknet drug markets </a> https://heinekenmarketdarknet.com/ - darknet market drug
名前
EdwardHal
the real deal market darknet <a href="https://kingdomonlinedrugs.com/ ">best darknet market may 2023 reddit </a> https://kingdomonlinedrugs.com/ - free deep web links
名前
Ronaldwrope
black market prescription drugs <a href="https://kingdom-darkmarket-online.com/ ">deep website search engine </a> https://kingdom-darkmarket-online.com/ - underground card shop
名前
Robertzeque
alphabay market net <a href="https://heinekenmarket-darknet.com/ ">reddit working darknet markets </a> https://heineken-markett.com/ - reddit onion list
名前
Williammulge
deep deep web links <a href="https://kingdom-drugs-market.com/ ">price of black market drugs </a> https://kingdom-drugs-market.com/ - dark web escrow service
名前
Albertobut
tor market links <a href="https://heinekenmarket-link.com/ ">darknet drug markets 2023 </a> https://heinekenmarket-link.com/ - darknet drugs germany
名前
JohnnyBiz
hitman for hire dark web <a href="https://kingdom-onlinedrugs.com/ ">archetyp url </a> https://kingdom-onlinedrugs.com/ - drug markets dark web
名前
Jimmyrox
<a href=https://geipzbw.artist-bio.ru/></a>
名前
wpwleciv
verified dark web links <a href="https://darkweb-kingdom.com/ ">dark markets bolivia </a> https://darkweb-kingdom.com/ - darknet vendor reviews
名前
BrettUttep
working darknet markets <a href="https://heinekenmarketplace24.com/ ">dark web legit sites </a> https://heineken-marketplace.com/ - darknet black market list
名前
CharlieZoose
darknet market security <a href="https://kingdomdrugsmarket.com/ ">assassination market darknet </a> https://kingdomdrugsmarketplace.com/ - darknet drugs
名前
ScottAduch
tor darknet market address <a href="https://heinekendarknetmarket.com/ ">darknet markets best </a> https://heinekenmarketdarknet.com/ - top onion links
名前
EdwardHal
<a href=https://bhahqof.artist-bio.ru/></a>
名前
kloavxey
step by step dark web <a href="https://heineken-markett.com/ ">how to browse the dark web reddit </a> https://heineken-markett.com/ - dark web shopping
名前
Williammulge
phenazepam pills <a href="https://heinekenmarket-link.com/ ">dark markets finland </a> https://heinekenmarket-link.com/ - darknet sites url
名前
JohnnyBiz
how to access deep web safely reddit <a href="https://kingdom-drugs-market.com/ ">darknet live stream </a> https://kingdom-drugs-market.com/ - deep sea darknet market
名前
Albertobut

コメントを追加

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