【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 reddit list <a href="https://darkfoxdarkwebdrugstore.com/ ">pax marketplace </a> https://darkfox-onion-darkmarket.com/ - how to access darknet markets
名前
Jancal
core market darknet <a href="https://darkweb-kingdom.com/ ">ruonion </a> https://darkweb-kingdom.com/ - deep web search engine 2023
名前
Teddred
dark markets czech republic <a href="https://heinekenmarket-link.com/ ">tor market darknet </a> https://heinekenmarket-link.com/ - darknet database market
名前
Robertfup
Abacus Market link <a href="https://heinekenoniondarkweb.com/ ">bitcoin market on darknet tor </a> https://heinekenoniondarkweb.com/ - darknet market francais
名前
RobertKix
how to access dark web markets <a href="https://kingdommarketdarknet.com/ ">darknet drug store </a> https://kingdommarketdarknet.com/ - darknet paypal accounts
名前
Tornaddib
darknet markets address <a href="https://kingdomdarknet.com/ ">best market darknet drugs </a> https://kingdomdarknet.com/ - black market access
名前
JamesHub
deep web links reddit 2023 <a href="https://dark-web-heineken.com/ ">dark web in spanish </a> https://dark-web-heineken.com/ - french dark web
名前
HaroldHot
darknet market dmt <a href="https://heineken-onion.com/ ">onion tube porn </a> https://heineken-onion.com/ - working dark web links
名前
Dannyquord
legit darknet markets <a href="https://drheinekenexpress.com/ ">tor2door market url </a> https://drheinekenexpress.com/ - darknet drug prices uk
名前
Richardvak
archetyp url <a href="https://kingdomdarkmarket.com/ ">Cocorico url </a> https://kingdomdarkmarket.com/ - online black marketplace
名前
Hanstulge
underground card shop <a href="https://heineken-drugsonline.com/ ">bohemia market url </a> https://heineken-drugs-market.com/ - black market website legit
名前
Brandendet
darknet stock market <a href="https://darkmarketkingdom.com/ ">deep web software market </a> https://darkmarketkingdom.com/ - darknet stock market
名前
FrankHuluh
current darknet market list <a href="https://kingdomdarknetmarket.com/ ">darknet market francais </a> https://darkfoxdarknetdrugstore.com/ - darknet market listing
名前
Crisscunc
links tor 2023 <a href="https://darkfox-onion-darkweb.com/ ">best darknet market 2023 reddit </a> https://darkfox-onion-darkweb.com/ - darknet site
名前
WilliamRip
darknet drugs safe <a href="https://heinekenmarketdarknet.com/ ">access darknet markets </a> https://heinekenmarketdarknet.com/ - project versus
名前
Josephanarm
cypher url <a href="https://heineken-onlinedrugs.com/ ">drugs dark web price </a> https://heineken-drugs-online.com/ - dark websites reddit
名前
Michaelloush
darknet market canada <a href="https://heinekenonionmarket.com/ ">best darknet market urs </a> https://heineken-online-drugs.com/ - dark market reddit
名前
Edgarlow
dark market sites <a href="https://kingdommarket-url.com/ ">dark markets romania </a> - best dark web links
名前
ADElugh
links tor 2023 <a href="https://heinekenonion.com/ ">darknet market search </a> https://heinekenonion.com/ - alphabay market url
名前
ZacharyBop
search deep web engine <a href="https://darkwebheineken.com/ ">biggest darknet market 2023 </a> https://darkwebheineken.com/ - darknet market for noobs
名前
BrianFew
darknet markets australia <a href="https://kingdom-darkmarket.com/ ">onion sex shop </a> https://kingdomdarkwebmarket.com/ - dark markets united kingdom
名前
Wendellpog
dark markets andorra <a href="https://darkfox-onlinedrugs.com/ ">dark markets turkey </a> https://darkfox-onlinedrugs.com/ - darknet prices
名前
Baaket
reddit darknet markets noobs <a href="https://kingdom-drugs-online.com/ ">top darknet markets </a> https://kingdom-drugs-online.com/ - dark markets 2023
名前
Shanewat
deep web drug url <a href="https://darkwebkingdom.com/ ">0day onion </a> https://darkwebkingdom.com/ - darknet market list links
名前
Danired
vice city link <a href="https://kingdomdarknetdrugstore.com/ ">darknet paypal accounts </a> https://kingdomdarknetdrugstore.com/ - bohemia link
名前
Geraldhopay
largest darknet market <a href="https://heinekenmarketonlinee.com/ ">Cocorico Market </a> https://heinekenn-express.com/ - how to anonymously use darknet markets
名前
Patrickhuple
darknet links markets <a href="https://heinekendrugsmarketplace.com/ ">alphabay market darknet </a> https://heinekendrugsmarketplace.com/ - open darknet markets
名前
MichaelRaf
darknet drug delivery <a href="https://heinekenmarketplace24.com/ ">darknet drug market list </a> https://heineken-marketplace.com/ - what darknet markets are open
名前
Georgelouse
current darknet market list <a href="https://heineken-darknet-drugstore.com/ ">dark net guide </a> https://heineken-darknet-drugstore.com/ - dark markets luxembourg
名前
HectorDer
deep web hitmen url <a href="https://kingdom-darkwebmarket.com/ ">onion dark web list </a> https://kingdom-darkmarketplace.com/ - darknet market onions
名前
JamesStaiz
blackweb darknet market <a href="https://kingdommarketonlinee.com/ ">reddit biggest darknet market place </a> https://kingdommarketonlinee.com/ - grey market darknet link
名前
SmittMef
dark markets sweden <a href="https://heineken-darkmarket-online.com/ ">grey market drugs </a> https://heinekendarkmarketonline.com/ - deep web markets
名前
Randykew
buying drugs on darknet <a href="https://darkweb-heineken.com/ ">darkweb marketplace </a> https://dark-market-heineken.com/ - largest darknet market
名前
Matthewgek
working darknet market links <a href="https://kingdomdrugsonline.com/ ">darknet markets up </a> https://kingdomdrugsonline.com/ - dark web markets
名前
Davidjoisp
dark markets ireland <a href="https://kingdomoniondarkmarket.com/ ">how to anonymously use darknet markets </a> https://kingdomoniondarkmarket.com/ - what darknet markets still work
名前
CraigAgeni
Kingdom Market darknet <a href="https://heineken-darkmarket.com/ ">reddit biggest darknet market place </a> https://heineken-darkmarket.com/ - dark markets canada
名前
DonaldDic
alphabay link reddit <a href="https://kingdom-darkweb.com/ ">how to access deep web safely reddit </a> https://kingdom-darknet.com/ - how to use darknet markets
名前
Granttromo
dark web links 2023 <a href="https://kingdom-onion-market.com/ ">archetyp market </a> https://kingdom-onion-darkmarket.com/ - good dark web search engines
名前
DamonLat
russian anonymous marketplace <a href="https://heineken-onion-market.com/ ">darknet drug markets </a> https://heineken-onion-darkmarket.com/ - tor markets 2023
名前
JackieDuart
uncensored deep web <a href="https://kingdom-darkweb-drugstore.com/ ">which darknet markets are still open </a> https://heinekenmarketplacee.com/ - deep sea darknet market
名前
Randytiz
assassination market darknet <a href="https://heineken-markett.com/ ">darknet onion links drugs </a> https://heinekenmarket-darknet.com/ - cp onion
名前
JamesseM
dark web link <a href="https://kingdomdrugsmarket.com/ ">dark web links market </a> https://kingdomdrugsmarketplace.com/ - current darknet markets
名前
Sirket
best darknet marketplaces <a href="https://heineken-darkwebmarket.com/ ">dark markets japan </a> https://heineken-darkmarketplace.com/ - dark market reddit
名前
JasonGribe
vice city link <a href="https://kingdom-dark-market.com/ ">dark web website links </a> https://kingdom-dark-market.com/ - darknet market wikia
名前
Ralphzet
bohemia url <a href="https://kingdom-darknet-drugstore.com/ ">dark markets macedonia </a> https://kingdom-darknet-drugstore.com/ - tor darknet
名前
Julianacecy
access the black market <a href="https://heinekenmarketlink.com/ ">back market trustworthy </a> https://heinekenmarket-url.com/ - reddit best darknet markets
名前
BrandonWaype
accessing darknet market <a href="https://kingdomonionmarket.com/ ">dark web escrow service </a> https://kingdomonionmarket.com/ - australian dark web markets
名前
Ronaldevica
darknet market ddos <a href="https://kingdom-darkmarket-online.com/ ">black market dark web links </a> https://kingdomdarkmarketonline.com/ - crypto darknet drug shop
名前
CharlesNuh
darknet market busts <a href="https://heinekendarknetdrugstore.com/ ">dark websites reddit </a> https://heinekendarknetdrugstore.com/ - how to buy from the darknet markets lsd
名前
RichardDek
best darknet markets for marijuana <a href="https://kingdommarket-links.com/ ">deep web cc shop </a> https://kingdommarket-darknet.com/ - red ferrari pills
名前
CorryViarD

コメントを追加

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