【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 bank accounts <a href="https://heinekenmarketurl.com/ ">2023 darknet markets </a> https://heinekenmarketurl.com/ - tor drugs
名前
Charlescob
market onion <a href="https://kingdommarketplacee.com/ ">drug website dark web </a> https://darkfox-onlinedrugs.com/ - bohemia market
名前
Baaket
dark web markets 2023 <a href="https://heinekenmarket-link.com/ ">what are darknet drug markets </a> https://heinekenmarket-links.com/ - versus link
名前
Robertfup
uncensored hidden wiki link <a href="https://kingdomdarkmarket.com/ ">trusted darknet vendors </a> https://kingdommarket-online.com/ - the real deal market darknet
名前
Hanstulge
popular dark websites <a href="https://darkmarket-heineken.com/ ">dark market </a> https://dark-web-heineken.com/ - darknet market canada
名前
HaroldHot
best darknet market for steroids <a href="https://heinekendarkmarket.com/ ">deep deep web links </a> https://heinekenmarket-online.com/ - archetyp market url
名前
DavidDes
dark markets australia <a href="https://kingdomdarkweb.com/ ">darknet market listing </a> https://kingdomdarkweb.com/ - naked lady ecstasy pill
名前
JamesHub
superman pills mg <a href="https://heineken-drugsonline.com/ ">alphabay market link </a> https://heineken-drugs-market.com/ - darknet market oxycontin
名前
Brandendet
top 10 dark websites <a href="https://heineken-onion.com/ ">pyramid pill </a> https://heineken-onion.com/ - fresh onions link
名前
Dannyquord
how to buy bitcoin for the dark web <a href="https://heinekennexpress.com/ ">credit card black market websites </a> https://heinekennexpress.com/ - darknet search
名前
Richardvak
dark markets usa <a href="https://heinekenonionmarket.com/ ">bitcoin drugs market </a> https://heinekenonionmarket.com/ - bitcoin drugs market
名前
Edgarlow
darknet market <a href="https://heinekendarkwebdrugstore.com/ ">dark websites reddit </a> https://heinekendarkwebdrugstore.com/ - reddit darknet market noobs
名前
HectorDer
dark web hitmen <a href="https://kingdom-onion-darkweb.com/ ">blacknet drugs </a> https://kingdomdarknetdrugstore.com/ - dark web cheap electronics
名前
Geraldhopay
dark web directory <a href="https://heinekenmarketdarknet.com/ ">darknet illegal market </a> https://heinekendarknetmarket.com/ - darknet market links 2023
名前
Josephanarm
buy darknet market email address <a href="https://kingdomonion.com/ ">dark markets belgium </a> https://darkmarketkingdom.com/ - grey market darknet
名前
FrankHuluh
best fraud market darknet <a href="https://darkmarketheineken.com/ ">links deep web tor </a> https://heinekenonion.com/ - bohemia link
名前
ZacharyBop
deep web drug store <a href="https://kingdom-onlinedrugs.com/ ">darknet market carding </a> https://kingdom-onlinedrugs.com/ - new dark web links
名前
Shanewat
deep web search engine 2023 <a href="https://kingdomdarkwebmarket.com/ ">asap darknet market </a> https://kingdomdarkwebmarket.com/ - darknet markets florida
名前
Wendellpog
deep market <a href="https://heinekendrugsmarketplace.com/ ">dark markets russia </a> https://heinekendrugsmarket.com/ - darknet drugs germany
名前
MichaelRaf
best darknet market australia <a href="https://heinekenmarketonlinee.com/ ">black market website legit </a> https://heinekenn-express.com/ - buying drugs online on openbazaar
名前
Patrickhuple
reddit darknet market links <a href="https://kingdom-darkmarketplace.com/ ">deep dark web markets links </a> https://kingdom-darkmarketplace.com/ - weed darknet market
名前
JamesStaiz
dark markets spain <a href="https://dark-web-kingdom.com/ ">blacknet drugs </a> https://dark-web-kingdom.com/ - current darknet markets reddit
名前
Danielred
australian darknet markets <a href="https://heinekendarkweb.com/ ">drugs on the darknet </a> https://heinekendarkweb.com/ - how big is the darknet market
名前
JuliusEsobe
how to buy things off the black market <a href="https://heineken-express-onion.com/ ">buy ssn and dob </a> https://heineken-express-onion.com/ - darknet market list 2023
名前
BrianFew
best darknet market 2023 <a href="https://heineken-marketplace.com/ ">how to buy from the darknet markets lsd </a> https://heinekenmarketplace24.com/ - how to buy from darknet
名前
Georgelouse
top darknet market now <a href="https://drkingdommarket.com/ ">darknet reddit market </a> https://drkingdommarket.com/ - dark markets austria
名前
SmittMef
vice city market link <a href="https://kingdom-onion-darkmarket.com/ ">best darknet market links </a> https://kingdom-onion-market.com/ - dark markets latvia
名前
DamonLat
dark markets bulgaria <a href="https://heineken-onion-market.com/ ">best darknet market may 2023 reddit </a> https://heineken-onion-darkmarket.com/ - dark markets finland
名前
JackieDuart
blockchain darknet markets <a href="https://heineken-darkmarket-online.com/ ">buy drugs darknet </a> https://heineken-darkmarket-online.com/ - onion link reddit
名前
Randykew
top darknet markets <a href="https://kingdomoniondarkmarket.com/ ">darknet onion markets reddit </a> https://kingdomoniondarkmarket.com/ - xanax darknet reddit
名前
CraigAgeni
dark markets brazil <a href="https://heinekendarkwebmarket.com/ ">where to find onion links </a> https://heineken-darkmarket.com/ - google black market
名前
DonaldDic
darknet drugs url <a href="https://dark-market-heineken.com/ ">bitcoin darknet markets </a> https://dark-market-heineken.com/ - counterfeit money onion
名前
Matthewgek
darknet drug store <a href="https://kingdom-darkweb.com/ ">darknet markets most popular </a> https://kingdom-darknet.com/ - how to get on the dark web
名前
Granttromo
deep web drugs <a href="https://kingdomonlinedrugs.com/ ">dark markets usa </a> https://kingdomonlinedrugs.com/ - dark web uk
名前
Davidjoisp
Abacus Market url <a href="https://dark-market-kingdom.com/ ">guide to darknet markets </a> https://darkweb-kingdom.com/ - how to get on darknet market
名前
Teddred
darknet market and monero <a href="https://kingdom-darkweb-drugstore.com/ ">how to access dark web markets </a> https://heinekenmarketplacee.com/ - tor best websites
名前
Randytiz
black market bank account <a href="https://heinekendarkmarketplace.com/ ">dark web links adult </a> https://heinekendarkmarketplace.com/ - hacking tools darknet markets
名前
TimmyMeexy
drugs dark web price <a href="https://kingdomdrugsmarket.com/ ">dark web market reviews </a> https://kingdomdrugsmarketplace.com/ - tor markets 2023
名前
Sirket
dark markets venezuela <a href="https://kingdomdarkwebdrugstore.com/ ">dark web engine search </a> https://kingdom-darknet-drugstore.com/ - best darknet markets reddit
名前
Julianacecy
australian dark web vendors <a href="https://darkfoxdarknetdrugstore.com/ ">biggest darknet markets </a> https://darkfoxdarknetdrugstore.com/ - dark markets brazil
名前
Crisscunc
darknet market litecoin <a href="https://heineken-darkmarketplace.com/ ">reliable darknet markets </a> https://heineken-darkwebmarket.com/ - working darknet markets 2023
名前
JasonGribe
deep onion links <a href="https://heineken-drugs-online.com/ ">best darknet market links </a> https://heineken-onlinedrugs.com/ - how to get on the dark web on laptop
名前
Michaelloush
how to anonymously use darknet markets <a href="https://heineken-markett.com/ ">darknet sites url </a> https://heinekenmarket-darknet.com/ - dark web market place links
名前
JamesseM
deep market <a href="https://kingdomdarkmarketplace.com/ ">darknet market list links </a> https://kingdom-dark-market.com/ - dark markets switzerland
名前
Ralphzet
darknet markets lsd-25 2023 <a href="https://kingdommarketdarknet.com/ ">blue lady e pill </a> https://kingdom-markett.com/ - dark markets thailand
名前
Tornaddib
illegal black market <a href="https://darkfoxdarkwebdrugstore.com/ ">list of darknet markets reddit </a> https://darkfox-onion-darkmarket.com/ - best market darknet drugs
名前
Jancal
reddit darknet markets links <a href="https://kingdom-darkmarket-online.com/ ">drug website dark web </a> https://kingdom-darkmarket-online.com/ - darknet market adderall
名前
CharlesNuh
dark web market place links <a href="https://darkfoxonionmarket.com/ ">darknet marketplace </a> https://darkfoxonlinedrugs.com/ - dark chart
名前
Davidinodo
dark markets moldova <a href="https://kingdom-drugsonline.com/ ">biggest darknet market 2023 </a> https://kingdom-drugsonline.com/ - xanax darknet reddit
名前
WilliamNaw
adress darknet <a href="https://heineken-onion-darkweb.com/ ">darknetlive </a> https://heineken-onion-darkweb.com/ - black market cryptocurrency
名前
RichardDek

コメントを追加

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