【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 market xanax <a href="https://darkwebkingdom.com/ ">dark markets italy </a> https://kingdom-onion.com/ - most popular darknet markets 2023
名前
Everettmus
darkfox market url <a href="https://kingdom-darkmarket-online.com/ ">dark net market list </a> https://kingdomdarkmarketonline.com/ - dark markets france
名前
Robertzeque
best darknet market for guns <a href="https://kingdomdarkmarketplace.com/ ">darknet prices </a> - darknet markets list 2023
名前
Ronaldtic
dark markets brazil <a href="https://heinekenmarketlink.com/ ">dark markets san marino </a> https://heinekenmarket-url.com/ - tor2door darknet market
名前
Wesleyenuse
darknet market superlist <a href="https://kingdomdrugsmarketplace.com/ ">drug website dark web </a> https://kingdomdrugsmarket.com/ - darknet seiten
名前
ScottAduch
dark web prostitution <a href="https://kingdomdrugsonline.com/ ">darkmarket </a> https://kingdomonlinedrugs.com/ - darknet escrow markets
名前
Ronaldwrope
live darknet markets <a href="https://kingdomdarknet.com/ ">best darknet market for psychedelics </a> https://kingdomdarknet.com/ - dark web market
名前
ElmerPralt
incognito market darknet <a href="https://darkmarketkingdom.com/ ">darkmarket link </a> https://darkmarketkingdom.com/ - bohemia market darknet
名前
Allenthuck
wiki darknet market <a href="https://heinekennexpress.com/ ">credit card dumps dark web </a> https://drheinekenexpress.com/ - alphabay market net
名前
ErnestHalry
dark markets brazil <a href="https://heinekenmarketonlinee.com/ ">dark market 2023 </a> https://heinekenn-express.com/ - cheap darknet websites dor drugs
名前
EdwardDride
what is escrow darknet markets <a href="https://heinekenexpressonion.com/ ">guide to darknet markets </a> https://heinekenexpressonion.com/ - safe list of darknet market links
名前
DavidLeape
versus project market link <a href="https://kingdom-drugs-market.com/ ">onion darknet market </a> https://kingdom-drugsonline.com/ - darknet drugs india
名前
Albertobut
darknet market superlist <a href="https://kingdom-darkweb.com/ ">accessing darknet market </a> https://kingdom-darkweb.com/ - darknet drug market url
名前
DevinImMek
black market dark web links <a href="https://heineken-marketplace.com/ ">counterfeit euro deep web </a> https://heineken-marketplace.com/ - Cocorico Market link
名前
CharlieZoose
links the hidden wiki <a href="https://darkwebheineken.com/ ">what darknet markets are still up </a> https://darkwebheineken.com/ - reddit darknet markets noobs
名前
Andrewbem
darknet drug markets reddit <a href="https://kingdommarketdarknet.com/ ">incognito market darknet </a> https://kingdom-markett.com/ - bitcoin dark web
名前
Robertduelf
dark markets monaco <a href="https://kingdomurl.com/ ">best darknet market 2023 </a> https://kingdommarketurl.com/ - dark markets brazil
名前
KevinClimi
darknet market links safe <a href="https://darkmarket-kingdom.com/ ">darknet online drugs </a> https://darkmarket-kingdom.com/ - updated darknet market list
名前
HenryHap
darknet market adressen <a href="https://heineken-darkmarket.com/ ">darknet website for drugs </a> https://heinekendarkwebmarket.com/ - list of darknet drug markets
名前
WillisVow
euroguns deep web <a href="https://kingdomdarkwebmarket.com/ ">counterfeit money deep web </a> https://kingdom-darkmarket.com/ - darknet paypal accounts
名前
WilliamUttep
darknet drug trafficking <a href="https://heinekendarknetmarket.com/ ">darknet market link updates </a> https://heinekendarknetmarket.com/ - best darknet market reddit 2023
名前
EdwardHal
darknet market steroids <a href="https://kingdom-onlinedrugs.com/ ">reddit biggest darknet market place </a> https://kingdom-onlinedrugs.com/ - alphabay market url
名前
Jimmyrox
versus darknet market <a href="https://heinekenmarket-darknet.com/ ">onion deep web search </a> https://heinekenmarket-darknet.com/ - black market sites 2023
名前
Williammulge
reddit darknet reviews <a href="https://heinekendarkmarketplace.com/ ">dark markets colombia </a> https://heinekendarkmarketplace.com/ - how to buy from the darknet markets
名前
RandyEduts
working darknet markets 2023 <a href="https://heinekenmarket-online.com/ ">darknet drug prices uk </a> https://heinekenmarket-online.com/ - deep web drug prices
名前
EugeneGor
darknet market and monero <a href="https://drkingdommarket.com/ ">darknet links market </a> https://kingdommarketonlinee.com/ - top darknet market 2023
名前
RichardIcott
darkmarkets <a href="https://heineken-darkmarketplace.com/ ">top 10 dark web url </a> https://heineken-darkmarketplace.com/ - how to access dark web markets
名前
Phillipget
darknet market updates 2023 <a href="https://heineken-darknet.com/ ">deep dot web links </a> https://heineken-darkweb.com/ - counterfeit money dark web reddit
名前
Arnoldinfop
top ten dark web sites <a href="https://kingdommarketlink.com/ ">darknet markets still up </a> https://kingdommarketlink.com/ - darknet serious market
名前
HenryMaync
darknet drugs <a href="https://kingdom-darkmarketplace.com/ ">incognito link </a> https://kingdom-darkmarketplace.com/ - Cocorico Market darknet
名前
Timothylen
dark markets australia <a href="https://heinekenmarket-links.com/ ">google black market </a> https://heinekenmarket-links.com/ - dark web drug marketplace
名前
JohnnyBiz
pill with crown on it <a href="https://kingdomdarkmarket.com/ ">black market online website </a> https://kingdomdarkmarket.com/ - darknet markets address
名前
Davidinton
cypher market link <a href="https://heinekendarknet.com/ ">dread onion </a> https://heinekendarkweb.com/ - deep web drugs
名前
Williamroubs
darknet market wiki <a href="https://kingdommarket-darknet.com/ ">reddit darknet market superlist </a> https://kingdommarket-darknet.com/ - darknet prices
名前
JamesMop
deep net links <a href="https://heinekenurl.com/ ">dark markets iceland </a> https://heinekenmarketurl.com/ - bitcoin drugs market
名前
AndrewTelve
darknet software market <a href="https://darkweb-kingdom.com/ ">where to find darknet market links </a> https://darkweb-kingdom.com/ - reliable darknet markets
名前
BrettUttep
underground hackers black market <a href="https://heinekendarkmarketonline.com/ ">darknet dream market link </a> https://heinekendarkmarketonline.com/ - credit card black market websites
名前
EdwardOppow
the darknet market reddit <a href="https://dark-web-heineken.com/ ">incognito market url </a> https://dark-web-heineken.com/ - darknet gun market
名前
DanielNoubs
google black market <a href="https://kingdom-onion.com/ ">how to buy from darknet </a> https://kingdom-onion.com/ - how to enter the black market online
名前
Everettmus
best dark web markets <a href="https://kingdomdarkmarketonline.com/ ">dark web cvv </a> https://kingdom-darkmarket-online.com/ - darkfox url
名前
Robertzeque
darknet market list 2023 <a href="https://kingdom-dark-market.com/ ">dark market onion </a> - darknet market noobs reddit
名前
Ronaldtic
alphabay market onion link <a href="https://heinekenonion.com/ ">darknet market avengers </a> https://heinekenonion.com/ - deep web markets
名前
Zacharywah
buy ssn and dob <a href="https://heinekenmarketlink.com/ ">darknet market alphabay </a> https://heinekenmarket-url.com/ - what darknet markets are up
名前
Wesleyenuse
2023 darknet market <a href="https://kingdomdrugsmarket.com/ ">archetyp link </a> https://kingdomdrugsmarketplace.com/ - dark markets united kingdom
名前
ScottAduch
darknet links markets <a href="https://kingdomonlinedrugs.com/ ">crypto market darknet </a> https://kingdomdrugsonline.com/ - how to install deep web
名前
Ronaldwrope
deep web drug store <a href="https://darkmarketkingdom.com/ ">best darknet marketplaces </a> https://darkmarketkingdom.com/ - drugs on deep web
名前
Allenthuck
black market deep <a href="https://drheinekenexpress.com/ ">reddit darknet reviews </a> https://drheinekenexpress.com/ - darknet market security
名前
ErnestHalry
darknet gun market <a href="https://heinekenn-express.com/ ">Kingdom Market darknet </a> https://heinekenn-express.com/ - ethereum darknet markets
名前
EdwardDride
Cocorico link <a href="https://kingdom-darknet.com/ ">hidden uncensored wiki </a> https://kingdom-darkweb.com/ - top ten dark web
名前
DevinImMek
dumps shop <a href="https://heinekenmarketplace24.com/ ">how to search the dark web reddit </a> https://heineken-marketplace.com/ - weed darknet market
名前
CharlieZoose

コメントを追加

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