【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 iceland <a href="https://kingdommarketurl.com/ ">darknet markets deepdotweb </a> https://kingdomurl.com/ - deep web directory onion
名前
KevinClimi
best darknet market 2023 <a href="https://kingdom-markett.com/ ">versus project market darknet </a> https://kingdom-markett.com/ - best darknet drug market 2023
名前
Robertduelf
top ten dark web <a href="https://heinekendarkwebmarket.com/ ">price of black market drugs </a> https://heinekendarkwebmarket.com/ - darknet markets japan
名前
WillisVow
vice city market url <a href="https://heinekenurl.com/ ">Kingdom url </a> https://heinekenurl.com/ - drugs on the deep web
名前
AndrewTelve
dark web market list <a href="https://heinekenmarket-link.com/ ">darknet onion links drugs </a> https://heinekenmarket-links.com/ - reddit darknet markets links
名前
JohnnyBiz
tor2door market link <a href="https://kingdomdarkmarketplace.com/ ">darknet market guide </a> - reddit darknet market list 2023
名前
Ronaldtic
bitcoin market on darknet tor <a href="https://kingdom-onlinedrugs.com/ ">drugs dark web </a> https://kingdom-onlinedrugs.com/ - cypher link
名前
Jimmyrox
hitman for hire dark web <a href="https://heinekenn-express.com/ ">tor2door market link </a> https://heinekenn-express.com/ - deep cp links
名前
EdwardDride
how to buy from the darknet markets lsd <a href="https://drheinekenexpress.com/ ">best darknet markets uk </a> https://heinekennexpress.com/ - deep web links 2023 reddit
名前
ErnestHalry
access darknet markets <a href="https://darkwebheineken.com/ ">wiki darknet market </a> https://darkwebheineken.com/ - alphabay link
名前
Andrewbem
drugs from darknet markets <a href="https://heineken-dark-market.com/ ">trusted darknet markets </a> https://heinekendarkmarketplace.com/ - popular darknet markets
名前
RandyEduts
redit safe darknet markets <a href="https://kingdom-darknet.com/ ">darknet список сайтов </a> https://kingdom-darknet.com/ - darknet serious market
名前
DevinImMek
reddit darknet markets links <a href="https://heineken-darkwebmarket.com/ ">dark web markets reddit 2023 </a> https://heineken-darkwebmarket.com/ - Abacus darknet Market
名前
Phillipget
counterfeit money dark web reddit <a href="https://heineken-darkweb.com/ ">top darknet drug sites </a> https://heineken-darkweb.com/ - monero darknet markets
名前
Arnoldinfop
reddit working darknet markets <a href="https://drkingdommarket.com/ ">drug trading website </a> https://drkingdommarket.com/ - darknet market 2023 reddit
名前
RichardIcott
deep web markets <a href="https://kingdom-darkmarket.com/ ">Kingdom darknet Market </a> https://kingdom-darkmarket.com/ - top 10 dark web url
名前
WilliamUttep
dn market <a href="https://heinekendarkweb.com/ ">onion market url </a> https://heinekendarknet.com/ - bohemia market
名前
Williamroubs
deep web drug links <a href="https://darkweb-kingdom.com/ ">best darknet markets reddit </a> https://darkweb-kingdom.com/ - darknet market alternatives
名前
BrettUttep
new alphabay darknet market <a href="https://heinekenmarketplace24.com/ ">how to use darknet markets </a> https://heineken-marketplace.com/ - dark markets lithuania
名前
CharlieZoose
how to search the dark web reddit <a href="https://kingdommarket-links.com/ ">darknet market reddit </a> https://kingdommarket-darknet.com/ - black market prescription drugs
名前
JamesMop
darknet market package <a href="https://heinekendarkmarket.com/ ">darknet market lightning network </a> [url=https://heinekenmarket-online.com/ ]counterfeit money deep web [/url]
名前
EugeneGor
how to browse the dark web reddit <a href="https://kingdomonion.com/ ">active darknet markets </a> https://kingdomonion.com/ - deep web directory onion
名前
Allenthuck
darknet market google <a href="https://heinekenonion.com/ ">the dark web shop </a> https://heinekenonion.com/ - darknet dream market
名前
Zacharywah
dark markets montenegro <a href="https://kingdomdrugsmarketplace.com/ ">darknet steroid markets </a> https://kingdomdrugsmarketplace.com/ - darknet links market
名前
ScottAduch
darknet market reddit <a href="https://heinekenmarketdarknet.com/ ">dark web links market </a> https://heinekenmarketdarknet.com/ - how to access deep web safely reddit
名前
EdwardHal
active darknet markets <a href="https://kingdomdrugsonline.com/ ">darknet bank accounts </a> https://kingdomonlinedrugs.com/ - darknet market package
名前
Ronaldwrope
drugs darknet vendors <a href="https://kingdomdarkmarket.com/ ">what is darknet markets </a> https://kingdommarket-online.com/ - buy drugs on darknet
名前
Davidinton
darknet market stats <a href="https://heineken-markett.com/ ">darknet market avengers </a> https://heinekenmarket-darknet.com/ - url hidden wiki
名前
Williammulge
darknet market steroids <a href="https://kingdomurl.com/ ">deep cp links </a> https://kingdommarketurl.com/ - darknet market ranking
名前
KevinClimi
darknet reddit market pills <a href="https://kingdommarketdarknet.com/ ">dark web market place links </a> https://kingdom-markett.com/ - the darknet markets
名前
Robertduelf
how to use darknet markets <a href="https://heineken-onion.com/ ">dark markets chile </a> https://heineken-onion.com/ - reliable darknet markets reddit
名前
DavidLeape
dark markets india <a href="https://heinekenurl.com/ ">weed only darknet market </a> https://heinekenmarketurl.com/ - dxm pills
名前
AndrewTelve
darknet black market list <a href="https://kingdom-drugsonline.com/ ">active darknet markets 2023 </a> https://kingdom-drugs-market.com/ - black market cryptocurrency
名前
Albertobut
darknet drugs market <a href="https://darkwebheineken.com/ ">dark markets luxembourg </a> https://heineken-express-onion.com/ - deep dot web links
名前
Andrewbem
shop online without cvv code <a href="https://heinekenn-express.com/ ">pax marketplace </a> https://heinekenmarketonlinee.com/ - active darknet markets
名前
EdwardDride
darknet adress <a href="https://drheinekenexpress.com/ ">russian darknet market </a> https://heinekennexpress.com/ - counterfeit money dark web reddit
名前
ErnestHalry
grey market link <a href="https://heineken-darkmarket.com/ ">reddit best darknet markets </a> https://heineken-darkmarket.com/ - Abacus Market darknet
名前
WillisVow
dark web shopping <a href="https://kingdomdarkmarketplace.com/ ">australian dark web vendors </a> - best darknet market for psychedelics
名前
Ronaldtic
darknet market francais <a href="https://darkmarket-kingdom.com/ ">darknet market sites </a> https://darkmarket-kingdom.com/ - updated darknet market list
名前
HenryHap
reddit darknet market 2023 <a href="https://kingdom-darknet.com/ ">dark markets ecuador </a> https://kingdom-darknet.com/ - best darknet market for lsd
名前
DevinImMek
biggest darknet market 2023 <a href="https://heinekenmarket-links.com/ ">reddit darknet markets list </a> https://heinekenmarket-link.com/ - darkfox market url
名前
JohnnyBiz
darknet markets australia <a href="https://kingdom-drugs-online.com/ ">new darknet marketplaces </a> https://kingdom-onlinedrugs.com/ - darknet market steroids
名前
Jimmyrox
bohemia market link <a href="https://heinekendarkmarketplace.com/ ">darknet drugs </a> https://heinekendarkmarketplace.com/ - best darknet market for lsd
名前
RandyEduts
links the hidden wiki <a href="https://heinekendarkmarket.com/ ">dark markets belgium </a> https://heinekenmarket-online.com/ - dark markets ukraine
名前
EugeneGor
buying drugs on the darknet <a href="https://drkingdommarket.com/ ">site onion liste </a> https://drkingdommarket.com/ - darknet market noobs guide
名前
RichardIcott
darknet market onions <a href="https://kingdom-darkmarketplace.com/ ">dark web step by step </a> https://kingdom-darkwebmarket.com/ - dark web login guide
名前
Timothylen
darkweb sites reddit <a href="https://darkwebkingdom.com/ ">darknet market list links </a> https://darkwebkingdom.com/ - working dark web links
名前
Everettmus
darknet drug vendors <a href="https://heineken-darkwebmarket.com/ ">best mdma vendor darknet market reddit </a> https://heineken-darkwebmarket.com/ - darknet market links reddit
名前
Phillipget
dot onion websites <a href="https://kingdom-darkmarket.com/ ">dark web search engines 2023 </a> https://kingdom-darkmarket.com/ - dark markets
名前
WilliamUttep
project versus <a href="https://heineken-darknet.com/ ">dark web weed </a> https://heineken-darkweb.com/ - xanax darknet markets reddit
名前
Arnoldinfop

コメントを追加

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