【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 chile <a href="https://heinekendarkwebmarket.com/ ">drugs onion </a> https://heinekendarkwebmarket.com/ - how to access the dark web safely reddit
名前
WillisVow
darknet market place search <a href="https://heinekenmarketplace24.com/ ">dark web market </a> https://heinekenmarketplace24.com/ - darknet market links 2023
名前
CharlieZoose
darknet in person drug sales <a href="https://darkfox-onion-darkweb.com/ ">onion live </a> https://kingdom-marketplace.com/ - best darknet market for lsd
名前
Jeromesob
dark web legit sites <a href="https://heinekenexpressonion.com/ ">best darknet market for weed </a> https://heinekenexpressonion.com/ - darknet guide
名前
DavidLeape
dark markets chile <a href="https://heineken-darkmarketplace.com/ ">best darknet market links </a> https://heineken-darkmarketplace.com/ - drugs on the darknet
名前
Phillipget
how to find the black market online <a href="https://darkmarket-heineken.com/ ">ethereum darknet markets </a> https://darkmarket-heineken.com/ - dark markets china
名前
DanielNoubs
step by step dark web <a href="https://heinekendarknet.com/ ">darknet markets with tobacco </a> https://heinekendarknet.com/ - darknet market pills vendor
名前
Williamroubs
online black market uk <a href="https://darkwebheineken.com/ ">black market website </a> https://heineken-express-onion.com/ - bohemia market darknet
名前
Andrewbem
dark web xanax <a href="https://kingdommarket-online.com/ ">dark markets indonesia </a> https://kingdommarket-online.com/ - darknet black market sites
名前
Davidinton
adress darknet <a href="https://kingdomoniondarkmarket.com/ ">blockchain darknet markets </a> https://kingdomoniondarkmarket.com/ - Kingdom link
名前
WesleyPex
dark web shopping <a href="https://kingdom-darkwebmarket.com/ ">darknet drug vendor that takes paypal </a> https://kingdom-darkmarketplace.com/ - bohemia link
名前
Timothylen
counterfeit money deep web <a href="https://heinekenurl.com/ ">darknet market oz </a> https://heinekenmarketurl.com/ - dark net market list reddit
名前
AndrewTelve
dark web cheap electronics <a href="https://kingdomonionmarket.com/ ">darknet market alaska </a> https://kingdom-online-drugs.com/ - tor market links 2023
名前
BillyNut
how to create a darknet market <a href="https://dark-market-kingdom.com/ ">deep web search engine 2023 </a> https://darkweb-kingdom.com/ - australian dark web vendors
名前
BrettUttep
how to find the black market online <a href="https://heinekendarknetmarket.com/ ">incognito market link </a> https://heinekenmarketdarknet.com/ - dark web uk
名前
EdwardHal
darknet buy drugs <a href="https://kingdom-onion-darkmarket.com/ ">dark markets ireland </a> https://kingdom-onion-market.com/ - darknet litecoin
名前
JamesGal
top ten deep web <a href="https://kingdommarket-darknet.com/ ">dark web drug markets </a> https://kingdommarket-darknet.com/ - tor market list
名前
JamesMop
best working darknet market 2023 <a href="https://heineken-markett.com/ ">adresse dark web </a> https://heinekenmarket-darknet.com/ - uk darknet markets
名前
Williammulge
Kingdom Market <a href="https://darkwebkingdom.com/ ">darknet markets florida </a> https://darkwebkingdom.com/ - steroid market darknet
名前
Everettmus
dark markets new zealand <a href="https://kingdomdarkmarketplace.com/ ">darknet seiten liste </a> - which darknet markets are still open
名前
Ronaldtic
best darknet market for counterfeit <a href="https://kingdom-darkmarket-online.com/ ">black market alternative </a> https://kingdom-darkmarket-online.com/ - darknet markets norway 2023
名前
Robertzeque
darknet market arrests <a href="https://kingdomdrugsmarket.com/ ">darknet drug links </a> https://kingdomdrugsmarketplace.com/ - dark web steroids
名前
ScottAduch
marijuana dark web <a href="https://heinekenmarket-url.com/ ">onion dark web list </a> https://heinekenmarketlink.com/ - onion link reddit
名前
Wesleyenuse
buy ssn dob with bitcoin <a href="https://kingdomdrugsonline.com/ ">we amsterdam </a> https://kingdomdrugsonline.com/ - bohemia market darknet
名前
Ronaldwrope
best website to buy cc <a href="https://kingdomdarknet.com/ ">tfmpp pills </a> https://kingdomdarknet.com/ - how to use darknet markets
名前
ElmerPralt
deep web links reddit 2023 <a href="https://kingdomonion.com/ ">working darknet markets 2023 </a> https://kingdomonion.com/ - deep web drugs reddit
名前
Allenthuck
dark web markets reddit <a href="https://kingdomdarkwebdrugstore.com/ ">deep web cc dumps </a> https://kingdom-darknet-drugstore.com/ - new alphabay darknet market
名前
DarrenMic
darknet drugs <a href="https://heinekenmarket-link.com/ ">darknet sites drugs </a> https://heinekenmarket-link.com/ - reddit darknetmarket
名前
JohnnyBiz
reddit onion list <a href="https://kingdom-darknet.com/ ">cypher url </a> https://kingdom-darknet.com/ - dark web weed
名前
DevinImMek
how to dark web reddit <a href="https://kingdom-onion-darkweb.com/ ">darknet markets wax weed </a> https://kingdom-onion-darkweb.com/ - Cocorico Market url
名前
IgnacioVorge
australian darknet vendors <a href="https://kingdom-drugs-market.com/ ">incognito market url </a> https://kingdom-drugs-market.com/ - dark web markets 2023
名前
Albertobut
darknet reddit market pills <a href="https://heinekennexpress.com/ ">hidden uncensored wiki </a> https://heinekennexpress.com/ - guide to using darknet markets
名前
ErnestHalry
what darknet markets are available <a href="https://heinekenn-express.com/ ">darknet market noobs step by step </a> https://heinekenmarketonlinee.com/ - onion marketplace drugs
名前
EdwardDride
site darknet onion <a href="https://heinekendarkwebmarket.com/ ">tor onion search </a> https://heinekendarkwebmarket.com/ - darknet drug prices reddit
名前
WillisVow
darknet markets reddit 2023 <a href="https://kingdomdarkwebmarket.com/ ">black market webshop </a> https://kingdomdarkwebmarket.com/ - largest darknet market
名前
WilliamUttep
reliable darknet markets reddit <a href="https://darkmarket-kingdom.com/ ">vice city market url </a> https://darkmarket-kingdom.com/ - dark web drugs bitcoin
名前
HenryHap
dark market url <a href="https://kingdom-onlinedrugs.com/ ">best darknet markets for vendors </a> https://kingdom-onlinedrugs.com/ - tor marketplaces
名前
Jimmyrox
0day onion <a href="https://heinekendarkmarketplace.com/ ">darknet guns market </a> https://heinekendarkmarketplace.com/ - dark web markets
名前
RandyEduts
tor darknet <a href="https://heinekenmarket-online.com/ ">dark markets moldova </a> https://heinekenmarket-online.com/ - darknet market
名前
EugeneGor
Cocorico url <a href="https://heineken-darkwebmarket.com/ ">bohemia darknet market </a> https://heineken-darkmarketplace.com/ - dark web drugs australia
名前
Phillipget
onion deep web wiki <a href="https://heinekendarkmarketonline.com/ ">Kingdom Market </a> https://heineken-darkmarket-online.com/ - darknet market list links
名前
EdwardOppow
new alphabay darknet market <a href="https://heineken-marketplace.com/ ">darknet markets florida </a> https://heineken-marketplace.com/ - wiki sticks drugs
名前
CharlieZoose
grey market darknet <a href="https://heineken-darkweb.com/ ">dark web sites for drugs </a> https://heineken-darknet.com/ - onion links 2023
名前
Arnoldinfop
grey market drugs <a href="https://dark-web-heineken.com/ ">search darknet market </a> https://dark-web-heineken.com/ - how to get to the black market online
名前
DanielNoubs
darknet xanax <a href="https://darkmarketheineken.com/ ">darknet market list </a> https://heinekenonion.com/ - dark market 2023
名前
Zacharywah
dark web illegal links <a href="https://heinekendarknetmarket.com/ ">deep web canada </a> https://heinekendarknetmarket.com/ - how to get on darknet market
名前
EdwardHal
top darknet market now <a href="https://heinekendarknet.com/ ">darkfox url </a> https://heinekendarkweb.com/ - counterfeit euro deep web
名前
Williamroubs
which darknet markets are still open <a href="https://kingdomdarkmarket.com/ ">superlist darknet markets </a> https://kingdommarket-online.com/ - archetyp url
名前
Davidinton
dark websites <a href="https://kingdom-darkmarketplace.com/ ">drug market darknet </a> https://kingdom-darkwebmarket.com/ - darknet markets list
名前
Timothylen
top 10 dark web url <a href="https://heineken-onion.com/ ">phenethylamine drugs </a> https://heinekenexpressonion.com/ - black market url deep web
名前
DavidLeape

コメントを追加

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