【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 list market <a href="https://kingdom-darknet.com/ ">Cocorico Market link </a> https://kingdom-darkweb.com/ - brick market
名前
DevinImMek
dark web website links <a href="https://heinekenmarket-darknet.com/ ">reddit biggest darknet market place </a> https://heinekenmarket-darknet.com/ - darknet drugs safe
名前
Williammulge
reddit darknet market australia <a href="https://darkwebkingdom.com/ ">dark chart </a> https://darkwebkingdom.com/ - deep web links 2023 reddit
名前
Everettmus
onion dark web list <a href="https://darkmarketheineken.com/ ">carding deep web links </a> https://heinekenonion.com/ - uk darknet markets
名前
Zacharywah
best deep web markets <a href="https://darkfoxonionmarket.com/ ">how to get on the dark web android </a> https://darkfoxonlinedrugs.com/ - best darknet market for lsd
名前
Davidven
dark markets colombia <a href="https://drheinekenexpress.com/ ">top dumps shop </a> https://drheinekenexpress.com/ - deep web markets
名前
ErnestHalry
trusted darknet vendors <a href="https://kingdom-drugsonline.com/ ">pax marketplace </a> https://kingdom-drugs-market.com/ - darknet black market list
名前
Albertobut
dnm xanax <a href="https://kingdomdarknetdrugstore.com/ ">darknet markets without login </a> https://kingdomdarknetdrugstore.com/ - darknet market wiki
名前
IgnacioVorge
black market access <a href="https://heinekenn-express.com/ ">links deep web tor </a> https://heinekenn-express.com/ - bohemia darknet market
名前
EdwardDride
online black marketplace <a href="https://kingdommarketdarknet.com/ ">illegal black market </a> https://kingdommarketdarknet.com/ - darknet market sites and how
名前
Robertduelf
best darknet market now <a href="https://kingdom-marketplace.com/ ">dark web marketplace </a> https://darkfox-onion-darkweb.com/ - top ten dark web
名前
Jeromesob
black market online <a href="https://heineken-onion.com/ ">top darknet markets </a> https://heinekenexpressonion.com/ - what darknet markets are live
名前
DavidLeape
darknet market superlist <a href="https://heineken-darkmarketplace.com/ ">darknet market security </a> https://heineken-darkwebmarket.com/ - drugs sold on dark web
名前
Phillipget
darknet market dmt <a href="https://darkwebheineken.com/ ">how to buy from the darknet markets lsd </a> https://heineken-express-onion.com/ - adresse dark web
名前
Andrewbem
best darknet market uk <a href="https://dark-web-kingdom.com/ ">darknet website for drugs </a> https://dark-web-kingdom.com/ - darknet market package
名前
HenryHap
darkfox market url <a href="https://kingdom-darkmarket.com/ ">what darknet markets are still up </a> https://kingdomdarkwebmarket.com/ - tor markets
名前
WilliamUttep
how to get on darknet market <a href="https://darkfox-onion-darkmarket.com/ ">tor websites reddit </a> https://darkfox-onion-darkmarket.com/ - adresse onion black market
名前
AlbertGlice
darknet market google <a href="https://kingdom-darknet-drugstore.com/ ">Abacus Market </a> https://kingdom-darknet-drugstore.com/ - versus project market url
名前
DarrenMic
how to access the dark web 2023 <a href="https://kingdom-drugs-online.com/ ">blacknet drugs </a> https://kingdom-onlinedrugs.com/ - best fraud market darknet
名前
Jimmyrox
dark markets argentina <a href="https://heinekendarkmarket.com/ ">darknet market and monero </a> https://heinekendarkmarket.com/ - darknet drug market list
名前
EugeneGor
alphabay url <a href="https://darkmarket-heineken.com/ ">dark web drugs bitcoin </a> https://dark-web-heineken.com/ - dark markets france
名前
DanielNoubs
darknet drug market <a href="https://darkfoxdarknetdrugstore.com/ ">darknet market comparison chart </a> https://kingdomdarknetmarket.com/ - darknet market updates 2023
名前
Stanleymet
darknet markets best <a href="https://drkingdommarket.com/ ">how to use deep web on pc </a> https://kingdommarketonlinee.com/ - dark markets uruguay
名前
RichardIcott
dark market list <a href="https://heinekenmarketplacee.com/ ">australian darknet vendors </a> https://heinekenmarketplacee.com/ - what darknet market to use now
名前
MichaelJet
the dark web links 2023 <a href="https://heinekendarkmarketplace.com/ ">popular darknet markets </a> https://heinekendarkmarketplace.com/ - darknet paypal accounts
名前
RandyEduts
darknet market litecoin <a href="https://kingdomdarkmarket.com/ ">dark markets 2023 </a> https://kingdommarket-online.com/ - darknet markets deepdotweb
名前
Davidinton
darknet litecoin <a href="https://kingdom-darkwebmarket.com/ ">Abacus Market darknet </a> https://kingdom-darkwebmarket.com/ - darknet market links
名前
Timothylen
onion dark web list <a href="https://kingdomonionmarket.com/ ">link darknet market </a> https://kingdom-online-drugs.com/ - drugs onion
名前
BillyNut
the darknet markets <a href="https://darkweb-kingdom.com/ ">dark markets australia </a> https://dark-market-kingdom.com/ - darknet market links reddit
名前
BrettUttep
buy drugs darknet <a href="https://heineken-marketplace.com/ ">darknet markets reddit </a> https://heinekenmarketplace24.com/ - Cocorico url
名前
CharlieZoose
asap url <a href="https://heinekenmarketlink.com/ ">darknet market fake id </a> https://heinekenmarketlink.com/ - pax marketplace
名前
Wesleyenuse
buy drugs darknet <a href="https://heineken-darknet.com/ ">exploit market darknet </a> https://heineken-darkweb.com/ - ketamine darknet market
名前
Arnoldinfop
how to access deep web safely reddit <a href="https://kingdom-darkmarket-online.com/ ">buy drugs darknet </a> https://kingdomdarkmarketonline.com/ - dark web sites name list
名前
Robertzeque
tor markets 2023 <a href="https://kingdomdarkmarketplace.com/ ">dark markets mexico </a> - onion domain and kingdom
名前
Ronaldtic
link darknet market <a href="https://heineken-darkmarket.com/ ">core market darknet </a> https://heineken-darkmarket.com/ - wikipedia darknet market
名前
WillisVow
darknet market google <a href="https://heinekendarknetmarket.com/ ">back market legit </a> https://heinekenmarketdarknet.com/ - dark markets france
名前
EdwardHal
what darknet markets sell fentanyl <a href="https://kingdomoniondarkmarket.com/ ">darknet drugs market </a> https://kingdomoniondarkmarket.com/ - black market illegal drugs
名前
WesleyPex
shop ccs carding <a href="https://kingdomdrugsmarket.com/ ">darknet markets norway 2023 </a> https://kingdomdrugsmarket.com/ - darknet telegram group
名前
ScottAduch
versus project market <a href="https://heinekenurl.com/ ">darknet xanax </a> https://heinekenurl.com/ - versus project darknet market
名前
AndrewTelve
french dark web <a href="https://heinekenmarket-darknet.com/ ">darknet market avengers </a> https://heineken-markett.com/ - darknet drug vendors
名前
Williammulge
dark web electronics <a href="https://kingdom-onion-market.com/ ">dma drug </a> https://kingdom-onion-market.com/ - darknet market vendor guide
名前
JamesGal
deep web marketplaces reddit <a href="https://kingdomdrugsonline.com/ ">new darknet marketplaces </a> https://kingdomdrugsonline.com/ - darknet markets most popular
名前
Ronaldwrope
darknet adressen <a href="https://kingdomonion.com/ ">dark web sites for drugs </a> https://kingdomonion.com/ - deep net websites
名前
Allenthuck
deep website search engine <a href="https://kingdomdarknet.com/ ">darknet websites drugs </a> https://kingdomdarknet.com/ - how to anonymously use darknet markets
名前
ElmerPralt
darknet drug prices reddit <a href="https://kingdom-darkweb.com/ ">florida darknet markets </a> https://kingdom-darknet.com/ - dark markets andorra
名前
DevinImMek
dark markets norway <a href="https://heineken-darkmarket-online.com/ ">darknet market noobs bible </a> https://heinekendarkmarketonline.com/ - dark markets albania
名前
EdwardOppow
url hidden wiki <a href="https://darkwebkingdom.com/ ">how to buy from the darknet markets lsd </a> https://darkwebkingdom.com/ - what is the darknet market
名前
Everettmus
why engineering college essay <a href="https://topiccasestudy.com/">asthma case study</a> why i want to be an engineer college essay
名前
Quatfuts
currently darknet markets <a href="https://heineken-darkmarketplace.com/ ">darknet black market sites </a> https://heineken-darkmarketplace.com/ - how to use deep web on pc
名前
Phillipget
darknet market onions <a href="https://drheinekenexpress.com/ ">dark markets south korea </a> https://heinekennexpress.com/ - online black market uk
名前
ErnestHalry

コメントを追加

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