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

カテゴリー

コメント

dark markets paraguay <a href="https://kingdomdarknet.com/ ">dark web sites </a> https://kingdomdarkweb.com/ - wiki darknet market
名前
JamesHub
tor market <a href="https://kingdomdarknetdrugstore.com/ ">darknet sites drugs </a> https://kingdom-onion-darkweb.com/ - top 10 dark websites
名前
Geraldhopay
dark web payment methods <a href="https://heineken-drugs-market.com/ ">dark web payment methods </a> https://heineken-drugs-market.com/ - darknet markets ranked 2023
名前
Brandendet
what darknet markets are live <a href="https://heineken-onion.com/ ">which darknet markets are up </a> https://heineken-onion.com/ - new alphabay darknet market
名前
Dannyquord
crypto darknet drug shop <a href="https://drheinekenexpress.com/ ">darknet union </a> https://drheinekenexpress.com/ - working darknet markets
名前
Richardvak
list of darknet drug markets <a href="https://heineken-darknet-drugstore.com/ ">what is escrow darknet markets </a> https://heineken-darknet-drugstore.com/ - darknet market noobs guide
名前
HectorDer
blackweb darknet market <a href="https://dark-web-kingdom.com/ ">darknet drugs links </a> [url=https://dark-web-kingdom.com/ ]darknet market credit cards [/url]
名前
Danielred
most reliable darknet markets <a href="https://heinekendarknetmarket.com/ ">darknet сайты список </a> https://heinekenmarketdarknet.com/ - best websites dark web
名前
Josephanarm
dark web markets <a href="https://kingdomonion.com/ ">dark markets montenegro </a> https://kingdomonion.com/ - counterfeit money deep web
名前
FrankHuluh
how to access the black market <a href="https://darkmarketheineken.com/ ">dark web sites </a> https://darkmarketheineken.com/ - active darknetmarkets
名前
ZacharyBop
the armory tor url <a href="https://kingdom-onion-market.com/ ">how to buy drugs on darknet </a> https://kingdom-onion-market.com/ - Heineken Express Market
名前
DamonLat
live onion <a href="https://kingdomdarkwebmarket.com/ ">deep deep web links </a> https://kingdomdarkwebmarket.com/ - pyramid pill
名前
Wendellpog
reddit onion list <a href="https://heinekendrugsmarketplace.com/ ">dark web sites for drugs </a> https://heinekendrugsmarketplace.com/ - reddit darknet markets links
名前
MichaelRaf
darknet reinkommen <a href="https://kingdom-onlinedrugs.com/ ">darknet market vendors </a> https://kingdom-drugs-online.com/ - Abacus Market url
名前
Shanewat
darknet drugs price <a href="https://heinekenn-express.com/ ">darknet markets lsd-25 2023 </a> https://heinekenmarketonlinee.com/ - darknet reddit market
名前
Patrickhuple
asap link <a href="https://kingdom-darkwebmarket.com/ ">dark markets india </a> https://kingdom-darkmarketplace.com/ - tor markets
名前
JamesStaiz
darknet markets lsd-25 2023 <a href="https://heinekendarknet.com/ ">buying drugs on the darknet </a> https://heinekendarkweb.com/ - Cocorico url
名前
JuliusEsobe
red ferrari pills <a href="https://kingdommarketonlinee.com/ ">xanax darknet reddit </a> https://kingdommarketonlinee.com/ - darknet market xanax
名前
SmittMef
onion seiten 2023 <a href="https://heineken-express-onion.com/ ">online onion market </a> https://heineken-express-onion.com/ - market links darknet
名前
BrianFew
darknet search <a href="https://heinekenmarketplace24.com/ ">dark markets indonesia </a> https://heinekenmarketplace24.com/ - dark markets france
名前
Georgelouse
dark websites reddit <a href="https://heineken-onion-market.com/ ">black market sites 2023 </a> https://heineken-onion-market.com/ - market links darknet
名前
JackieDuart
deepdotweb markets <a href="https://dark-market-kingdom.com/ ">versus project market link </a> https://dark-market-kingdom.com/ - darknet litecoin
名前
Teddred
dark markets monaco <a href="https://heinekendarkmarketonline.com/ ">current darknet markets </a> https://heineken-darkmarket-online.com/ - dark markets andorra
名前
Randykew
darknet market listing <a href="https://kingdomoniondarkmarket.com/ ">how to access darknet markets reddit </a> https://kingdomoniondarkweb.com/ - best darknet markets for marijuana
名前
CraigAgeni
blacknet drugs <a href="https://heinekendarkwebmarket.com/ ">decentralized darknet market </a> https://heinekendarkwebmarket.com/ - darknet markets reddit links
名前
DonaldDic
crypto darknet drug shop <a href="https://kingdom-darknet-drugstore.com/ ">darknet markets japan </a> https://kingdom-darknet-drugstore.com/ - how to use deep web on pc
名前
Julianacecy
dark markets uk <a href="https://darkweb-heineken.com/ ">darkmarket url </a> https://darkweb-heineken.com/ - top 10 dark websites
名前
Matthewgek
darknet markets for steroids <a href="https://kingdom-darknet.com/ ">darknet market onions </a> https://kingdom-darknet.com/ - best dark web markets 2023
名前
Granttromo
reddit where to buy drugs <a href="https://kingdomonlinedrugs.com/ ">mdm love drug </a> https://kingdomonlinedrugs.com/ - deep web marketplaces reddit
名前
Davidjoisp
dark web drugs nz <a href="https://heinekenmarketplacee.com/ ">darknet market ddos </a> https://heinekenmarketplacee.com/ - dark markets montenegro
名前
Randytiz
darknet markets with tobacco <a href="https://heinekendarkmarketplace.com/ ">reliable darknet markets </a> https://heinekendarkmarketplace.com/ - dark markets malta
名前
TimmyMeexy
florida darknet markets <a href="https://kingdomdrugsmarketplace.com/ ">what is the darknet market </a> https://kingdomdrugsmarket.com/ - dark web markets 2023 australia
名前
Sirket
best fraud market darknet <a href="https://darkfoxonlinedrugs.com/ ">deep web directory onion </a> https://darkfoxonlinedrugs.com/ - list of darknet drug markets
名前
Davidinodo
dark web drugs bitcoin <a href="https://darkwebkingdom.com/ ">cypher link </a> https://kingdom-onion.com/ - darknet market adderall prices
名前
Danired
Abacus link <a href="https://darkfoxdarknetdrugstore.com/ ">alphabay market url </a> https://darkfoxdarknetdrugstore.com/ - sichere darknet markets 2023
名前
Crisscunc
best darknet market links <a href="https://heineken-onlinedrugs.com/ ">dark markets korea </a> https://heineken-drugs-online.com/ - versus link
名前
Michaelloush
dark web markets 2023 <a href="https://heineken-darkmarketplace.com/ ">most popular darknet markets 2023 </a> https://heineken-darkwebmarket.com/ - dark markets slovakia
名前
JasonGribe
darknet drugs sales <a href="https://kingdom-dark-market.com/ ">dark markets norway </a> https://kingdom-dark-market.com/ - dark web sites drugs
名前
Ralphzet
deep web canada <a href="https://heinekenmarket-darknet.com/ ">darknet markets that take ethereum </a> https://heineken-markett.com/ - dark markets monaco
名前
JamesseM
tor market url <a href="https://kingdom-darkmarket-online.com/ ">reddit working darknet markets </a> https://kingdomdarkmarketonline.com/ - best darknet market for weed 2023
名前
CharlesNuh
darknet market ranking <a href="https://heinekendarknetdrugstore.com/ ">buying drugs online on openbazaar </a> https://heineken-onion-darkweb.com/ - deep web links updated
名前
RichardDek
best darknet market for steroids <a href="https://kingdom-drugsonline.com/ ">dream market darknet link </a> https://kingdom-drugs-market.com/ - darknet market links buy ssn
名前
WilliamNaw
dark websites reddit <a href="https://kingdomonionmarket.com/ ">tor search engine link </a> https://kingdom-online-drugs.com/ - russian darknet market
名前
Ronaldevica
darknet markets with tobacco <a href="https://kingdommarketdarknet.com/ ">darknet website for drugs </a> https://kingdom-markett.com/ - Kingdom Market link
名前
Tornaddib
darknet market that has ssn database <a href="https://darkfox-onion-darkmarket.com/ ">drugs on the deep web </a> https://darkfoxdarkwebdrugstore.com/ - darknet seiten liste
名前
Jancal
tor link search engine <a href="https://heinekenmarket-url.com/ ">darknet market script </a> https://heinekenmarketlink.com/ - dark net market list
名前
BrandonWaype
buying darknet drugs <a href="https://heinekenoniondarkmarket.com/ ">best darknet markets reddit </a> https://heinekenoniondarkmarket.com/ - darknet market prices
名前
RobertKix
darknet markets with tobacco <a href="https://heinekenonlinedrugs.com/ ">darknet seiten liste </a> https://heinekenonlinedrugs.com/ - how to access the dark web on pc
名前
Stevejails
how to find the black market online <a href="https://heineken-darknet.com/ ">darknet market list 2023 </a> https://heineken-darkweb.com/ - darknet stock market
名前
Michaeltus
darkmarket link <a href="https://kingdom-marketplace.com/ ">dark markets belgium </a> https://darkfox-onion-darkweb.com/ - trusted darknet markets
名前
WilliamRip

コメントを追加

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