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

カテゴリー

コメント

deep web search engine url <a href="https://kingdomdarkmarket.com/ ">dark web sites for drugs </a> https://kingdomdarkmarket.com/ - dark markets singapore
名前
Hanstulge
back market trustworthy <a href="https://heineken-drugs-market.com/ ">deep web drug prices </a> https://heineken-drugsonline.com/ - darknet markets urls
名前
Brandendet
dark web market links <a href="https://drheinekenexpress.com/ ">anadrol pills </a> https://drheinekenexpress.com/ - phenethylamine drugs
名前
Richardvak
dark web search engines link <a href="https://kingdomdarknetmarket.com/ ">dark web hitman for hire </a> https://kingdomdarknetmarket.com/ - darknetlive
名前
Crisscunc
dark market onion <a href="https://darkmarketkingdom.com/ ">dark web login guide </a> https://darkmarketkingdom.com/ - how to access dark web markets
名前
FrankHuluh
deep web cc dumps <a href="https://heinekendarknetmarket.com/ ">working darknet markets </a> https://heinekenmarketdarknet.com/ - list of darknet markets 2023
名前
Josephanarm
what bitcoins are accepted by darknet markets <a href="https://kingdommarketlink.com/ ">darknet market directory </a> - dark web drugs nz
名前
ADElugh
darknet drug vendor that takes paypal <a href="https://darkmarketheineken.com/ ">underground market place darknet </a> https://darkmarketheineken.com/ - Cocorico Market darknet
名前
ZacharyBop
darknet escrow <a href="https://kingdom-onion-market.com/ ">dark web site list </a> https://kingdom-onion-darkmarket.com/ - Heineken Express darknet Market
名前
DamonLat
darknet market reddit 2023 <a href="https://kingdomdarkwebmarket.com/ ">darknet market noobs </a> https://kingdomdarkwebmarket.com/ - best darknet market for psychedelics
名前
Wendellpog
online drug market <a href="https://darkwebheineken.com/ ">darknet onion markets </a> https://darkwebheineken.com/ - darknet onion markets
名前
BrianFew
dark markets austria <a href="https://kingdom-drugs-online.com/ ">project versus </a> https://kingdom-onlinedrugs.com/ - darknet market onions
名前
Shanewat
dark market reddit <a href="https://heinekenonionmarket.com/ ">best darknet market for lsd </a> https://heineken-online-drugs.com/ - how to use onion sites
名前
Edgarlow
brucelean darknet market <a href="https://heinekenmarketonlinee.com/ ">best australian darknet market </a> https://heinekenmarketonlinee.com/ - dark market list
名前
Patrickhuple
darknet list <a href="https://heinekendrugsmarketplace.com/ ">black market url deep web </a> https://heinekendrugsmarketplace.com/ - dark markets malta
名前
MichaelRaf
darknet markets ranked 2023 <a href="https://heineken-darknet-drugstore.com/ ">onion link reddit </a> https://heinekendarkwebdrugstore.com/ - tor2door market url
名前
HectorDer
best darknet market for guns <a href="https://heinekenmarketplace24.com/ ">best darknet market 2023 </a> https://heinekenmarketplace24.com/ - dark markets south korea
名前
Georgelouse
drugs on the darknet <a href="https://kingdom-darkwebmarket.com/ ">darknet illegal market </a> https://kingdom-darkmarketplace.com/ - site darknet fermГ©
名前
JamesStaiz
incognito market <a href="https://kingdommarketonlinee.com/ ">archetyp link </a> https://kingdommarketonlinee.com/ - best drug darknet
名前
SmittMef
how to get to the black market online <a href="https://heineken-darkmarket-online.com/ ">what is a darknet drug market like </a> https://heineken-darkmarket-online.com/ - dark markets latvia
名前
Randykew
darknet drugs shipping <a href="https://kingdomonlinedrugs.com/ ">darknet drug delivery </a> https://kingdomonlinedrugs.com/ - dark markets paraguay
名前
Davidjoisp
tor search onion link <a href="https://kingdomoniondarkmarket.com/ ">dark web search tool </a> https://kingdomoniondarkweb.com/ - bitcoin market on darknet tor
名前
CraigAgeni
darknet market onions <a href="https://darkweb-heineken.com/ ">best darknet market for weed 2023 </a> https://dark-market-heineken.com/ - darknet black market url
名前
Matthewgek
darknet markets up <a href="https://heinekendarkwebmarket.com/ ">which darknet market are still up </a> https://heinekendarkwebmarket.com/ - asap market darknet
名前
DonaldDic
dark web drugs <a href="https://kingdom-darkweb.com/ ">Cocorico Market url </a> https://kingdom-darknet.com/ - dark markets portugal
名前
Granttromo
tor market url <a href="https://kingdom-darknet-drugstore.com/ ">how to access the dark web through tor </a> https://kingdom-darknet-drugstore.com/ - darknet market list
名前
Julianacecy
drug trading website <a href="https://heineken-onion-market.com/ ">dark web cheap electronics </a> https://heineken-onion-market.com/ - dark markets japan
名前
JackieDuart
reliable darknet markets lsd <a href="https://dark-web-kingdom.com/ ">what is escrow darknet markets </a> https://dark-web-kingdom.com/ - dark web illegal links
名前
Danielred
black market net <a href="https://heinekenmarketplacee.com/ ">darkweb markets </a> https://kingdom-darkweb-drugstore.com/ - darknet market sites
名前
Randytiz
best darknet markets uk <a href="https://heinekenmarket-darknet.com/ ">weed only darknet market </a> https://heinekenmarket-darknet.com/ - darknet market links safe
名前
JamesseM
darkfox market <a href="https://kingdomdrugsmarketplace.com/ ">online onion market </a> https://kingdomdrugsmarket.com/ - dark web trading
名前
Sirket
darknet new market link <a href="https://heineken-darkwebmarket.com/ ">darknet market noobs guide </a> https://heineken-darkmarketplace.com/ - how to get on the dark web
名前
JasonGribe
drugs dark web price <a href="https://kingdomdarkmarketplace.com/ ">best current darknet market </a> https://kingdom-dark-market.com/ - darknet market search engine
名前
Ralphzet
darknet black market <a href="https://darkfoxonionmarket.com/ ">tor darknet market </a> https://darkfoxonlinedrugs.com/ - top 10 dark web url
名前
Davidinodo
dread onion <a href="https://heinekenmarketlink.com/ ">Heineken Express Market </a> https://heinekenmarket-url.com/ - onion links credit card
名前
BrandonWaype
darknet markets availability <a href="https://kingdomonionmarket.com/ ">buying credit cards on dark web </a> https://kingdom-online-drugs.com/ - darknet markets onion address
名前
Ronaldevica
dynabolts pills <a href="https://dark-market-kingdom.com/ ">reddit darknetmarket </a> https://darkweb-kingdom.com/ - deep cp links
名前
Teddred
brucelean darknet market <a href="https://heinekendarknetdrugstore.com/ ">darknet market script </a> https://heineken-onion-darkweb.com/ - darknet escrow
名前
RichardDek
dark web legit sites <a href="https://kingdom-darkmarket-online.com/ ">darknet market links </a> https://kingdomdarkmarketonline.com/ - dark markets belgium
名前
CharlesNuh
darknet gun market <a href="https://kingdom-drugsonline.com/ ">darknet market controlled delivery </a> https://kingdom-drugs-market.com/ - dark web live
名前
WilliamNaw
darknet market buying mdma usa <a href="https://heineken-darknet.com/ ">versus link </a> https://heineken-darkweb.com/ - buying drugs online on openbazaar
名前
Michaeltus
blackweb darknet market <a href="https://heinekenonlinedrugs.com/ ">darknet drugs sales </a> https://heinekendrugsonline.com/ - how to search the dark web reddit
名前
Stevejails
tor dark web <a href="https://heinekenmarketurl.com/ ">darknet links markets </a> https://heinekenmarketurl.com/ - buying from darknet market with electrum
名前
Charlescob
accessing darknet market <a href="https://kingdommarket-links.com/ ">darknet market litecoin </a> https://kingdommarket-darknet.com/ - buy darknet market email address
名前
CorryViarD
best darknet market for weed <a href="https://kingdommarketurl.com/ ">darknet drugs url </a> https://kingdommarketurl.com/ - current darknet markets
名前
Hellyzes
dark markets luxembourg <a href="https://darkfox-onion-darkmarket.com/ ">drugs darknet vendors </a> https://darkfox-onion-darkmarket.com/ - weed only darknet market
名前
Jancal
how to anonymously use darknet markets <a href="https://heinekenmarket-link.com/ ">adresse onion black market </a> https://heinekenmarket-link.com/ - darknet search engine url
名前
Robertfup
largest darknet market <a href="https://kingdom-markett.com/ ">dark net market links 2023 </a> https://kingdom-markett.com/ - black market prescription drugs
名前
Tornaddib
black market drugs <a href="https://kingdomdarkweb.com/ ">back market legit </a> https://kingdomdarknet.com/ - dream market darknet
名前
JamesHub
euroguns deep web <a href="https://heinekenoniondarkmarket.com/ ">darknet markets reddit 2023 </a> https://heinekenoniondarkweb.com/ - dark markets chile
名前
RobertKix

コメントを追加

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