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

カテゴリー

コメント

black market online website <a href="https://kingdomdarkwebmarket.com/ ">darknet websites list 2023 </a> https://kingdomdarkwebmarket.com/ - darknet search engine
名前
WilliamUttep
best darknet markets reddit <a href="https://kingdom-onlinedrugs.com/ ">the real deal market darknet </a> https://kingdom-drugs-online.com/ - urls for darknet markets
名前
Jimmyrox
versus project market url <a href="https://heineken-marketplace.com/ ">how to enter the black market online </a> https://heineken-marketplace.com/ - darknet market directory
名前
CharlieZoose
darknet sites <a href="https://darkfox-onlinedrugs.com/ ">deep web links reddit </a>
名前
Baaket
tor2door market url <a href="https://heineken-dark-market.com/ ">darknet drug store </a> https://heineken-dark-market.com/ - biggest darknet market 2023
名前
RandyEduts
darknet markets 2023 reddit <a href="https://kingdommarketurl.com/ ">dark web drugs </a> https://kingdomurl.com/ - dark markets austria
名前
KevinClimi
uncensored hidden wiki link <a href="https://kingdommarketdarknet.com/ ">tor search onion link </a> https://kingdommarketdarknet.com/ - dark market url
名前
Robertduelf
darknet market reviews <a href="https://heinekendarkmarket.com/ ">pill with crown on it </a> https://heinekenmarket-online.com/ - darknet drug markets 2023
名前
EugeneGor
darknet seiten dream market <a href="https://heineken-darkwebmarket.com/ ">best darknet market 2023 </a> https://heineken-darkwebmarket.com/ - dark websites
名前
Phillipget
dark web directory <a href="https://heinekenmarketdarknet.com/ ">current darknet markets </a> https://heinekenmarketdarknet.com/ - darknet list
名前
EdwardHal
buy darknet market email address <a href="https://heinekenmarket-darknet.com/ ">site onion liste </a> https://heineken-markett.com/ - dark web drugs nz
名前
Williammulge
black market dark web links <a href="https://heineken-darknet.com/ ">how to access the black market </a> https://heineken-darknet.com/ - how to buy from the darknet markets lsd
名前
Arnoldinfop
active darknet markets 2023 <a href="https://drkingdommarket.com/ ">asap market link </a> https://kingdommarketonlinee.com/ - dark web market place links
名前
RichardIcott
darkweb markets <a href="https://kingdom-darkwebmarket.com/ ">buying drugs online on openbazaar </a> https://kingdom-darkmarketplace.com/ - darknet market bust
名前
Timothylen
black market webshop <a href="https://kingdommarket-online.com/ ">litecoin darknet markets </a> https://kingdomdarkmarket.com/ - bohemia darknet market
名前
Davidinton
darknet markets most popular <a href="https://kingdommarket-url.com/ ">dark markets malaysia </a> https://kingdommarket-url.com/ - darknet drugs sites
名前
HenryMaync
back market trustworthy <a href="https://heinekendarkweb.com/ ">Kingdom darknet Market </a> https://heinekendarkweb.com/ - darknet список сайтов
名前
Williamroubs
darknet markets fake id <a href="https://heineken-darkmarket-online.com/ ">darknet links markets </a> https://heinekendarkmarketonline.com/ - new darknet market reddit
名前
EdwardOppow
darknet market reddit list <a href="https://kingdommarket-links.com/ ">darknet market noobs reddit </a> https://kingdommarket-links.com/ - the dark market
名前
JamesMop
market street darknet <a href="https://darkweb-kingdom.com/ ">black market prescription drugs </a> https://darkweb-kingdom.com/ - incognito url
名前
BrettUttep
dark markets united kingdom <a href="https://heinekenmarketurl.com/ ">darknet market stats </a> https://heinekenmarketurl.com/ - cypher market
名前
AndrewTelve
darknet markets up <a href="https://darkmarket-heineken.com/ ">darkmarkets </a> https://dark-web-heineken.com/ - vice city market
名前
DanielNoubs
dark web illegal links <a href="https://heinekenonion.com/ ">dark websites reddit </a> https://darkmarketheineken.com/ - best darknet markets for vendors
名前
Zacharywah
darknet market directory <a href="https://heinekenmarket-link.com/ ">unicorn pill </a> https://heinekenmarket-links.com/ - dark markets hungary
名前
JohnnyBiz
deep web cc shop <a href="https://darkwebkingdom.com/ ">dark web markets 2023 </a> https://kingdom-onion.com/ - dark markets japan
名前
Everettmus
credit card dumps dark web <a href="https://kingdomdarkmarketonline.com/ ">deep dark web markets links </a> https://kingdom-darkmarket-online.com/ - how to enter the black market online
名前
Robertzeque
best lsd darknet market <a href="https://kingdom-dark-market.com/ ">dark markets belarus </a> - Cocorico Market darknet
名前
Ronaldtic
new onion darknet market <a href="https://heinekenmarketlink.com/ ">dark markets finland </a> https://heinekenmarket-url.com/ - Cocorico darknet Market
名前
Wesleyenuse
versus market url <a href="https://kingdomdrugsmarketplace.com/ ">what is a darknet drug market like </a> https://kingdomdrugsmarket.com/ - anadrol pills
名前
ScottAduch
nike jordan pill <a href="https://heinekenexpressonion.com/ ">how to access the darknet market </a> https://heinekenexpressonion.com/ - darknet cannabis markets
名前
DavidLeape
darknet market comparison chart <a href="https://kingdomonlinedrugs.com/ ">how to find the black market online </a> https://kingdomdrugsonline.com/ - darknet marketplace drugs
名前
Ronaldwrope
darknet market list <a href="https://kingdomonion.com/ ">dark web market </a> https://darkmarketkingdom.com/ - steroid market darknet
名前
Allenthuck
top darknet drug sites <a href="https://kingdomdarkweb.com/ ">Kingdom Market darknet </a> https://kingdomdarkweb.com/ - dark markets finland
名前
ElmerPralt
dark markets malaysia <a href="https://darkwebheineken.com/ ">dark web links reddit </a> https://darkwebheineken.com/ - wikipedia darknet market
名前
Andrewbem
drugs dark web <a href="https://kingdom-drugsonline.com/ ">orange sunshine lsd </a> https://kingdom-drugsonline.com/ - darknet drug prices reddit
名前
Albertobut
deep dot web replacement <a href="https://heinekenn-express.com/ ">reddit darknet markets list </a> https://heinekenn-express.com/ - darknet market comparison chart
名前
EdwardDride
darknet market directory <a href="https://heinekennexpress.com/ ">deep web links 2023 reddit </a> https://heinekennexpress.com/ - dark web weed
名前
ErnestHalry
dark markets macedonia <a href="https://dark-web-kingdom.com/ ">access the black market </a> https://darkmarket-kingdom.com/ - darknet reddit market
名前
HenryHap
Abacus Market darknet <a href="https://heineken-darkmarket.com/ ">the dark market </a> https://heineken-darkmarket.com/ - working dark web links
名前
WillisVow
how to buy from darknet markets <a href="https://kingdom-darkmarket.com/ ">core market darknet </a> https://kingdom-darkmarket.com/ - best darknet gun market
名前
WilliamUttep
best darknet market for steroids <a href="https://heineken-marketplace.com/ ">darknet drug market list </a> https://heineken-marketplace.com/ - deep web links 2023 reddit
名前
CharlieZoose
how to search the dark web reddit <a href="https://kingdom-onlinedrugs.com/ ">dark markets bulgaria </a> https://kingdom-onlinedrugs.com/ - working dark web links
名前
Jimmyrox
new onion darknet market <a href="https://kingdomurl.com/ ">ordering drugs on dark web </a> https://kingdommarketurl.com/ - dark web markets reddit
名前
KevinClimi
darkmarket <a href="https://kingdom-markett.com/ ">dark markets spain </a> https://kingdommarketdarknet.com/ - tor best websites
名前
Robertduelf
darknet markets reddit links <a href="https://heineken-dark-market.com/ ">top ten deep web </a> https://heineken-dark-market.com/ - xanax darknet reddit
名前
RandyEduts
fullz darknet market <a href="https://heinekendarkmarket.com/ ">top ten deep web </a> https://heinekenmarket-online.com/ - archetyp market darknet
名前
EugeneGor
black market prescription drugs for sale <a href="https://heinekenmarketdarknet.com/ ">top 10 dark websites </a> https://heinekendarknetmarket.com/ - credit card dumps dark web
名前
EdwardHal
darkmarket link <a href="https://heineken-markett.com/ ">drugs dark web price </a> https://heinekenmarket-darknet.com/ - dark websites reddit
名前
Williammulge
asap market darknet <a href="https://heineken-darkwebmarket.com/ ">darknet sites </a> https://heineken-darkmarketplace.com/ - incognito url
名前
Phillipget
how to enter the black market online <a href="https://kingdommarketonlinee.com/ ">google black market </a> https://drkingdommarket.com/ - dark markets netherlands
名前
RichardIcott

コメントを追加

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