【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>

カテゴリー

コメント

online drug market <a href="https://drkingdommarket.com/ ">dark markets croatia </a> https://kingdommarketonlinee.com/ - tor websites reddit
名前
SmittMef
2023 working darknet market <a href="https://heineken-darkmarket-online.com/ ">Heineken Express url </a> https://heineken-darkmarket-online.com/ - how to access the darknet market
名前
Randykew
hidden wiki tor onion urls directories <a href="https://kingdomonlinedrugs.com/ ">reddit working darknet markets </a> https://kingdomonlinedrugs.com/ - which darknet markets are still open
名前
Davidjoisp
darknet markets fake id <a href="https://kingdomoniondarkweb.com/ ">buying drugs off darknet </a> https://kingdomoniondarkmarket.com/ - deep web hitmen url
名前
CraigAgeni
deep web weed prices <a href="https://heineken-darkmarket.com/ ">drugs on deep web </a> https://heinekendarkwebmarket.com/ - darknet market lightning network
名前
DonaldDic
trusted darknet markets <a href="https://dark-market-heineken.com/ ">Cocorico url </a> https://darkweb-heineken.com/ - top darknet markets list
名前
Matthewgek
decabol pills <a href="https://heineken-onion-market.com/ ">versus market link </a> https://heineken-onion-market.com/ - grey market link
名前
JackieDuart
dark markets iceland <a href="https://kingdom-darkweb.com/ ">euroguns deep web </a> https://kingdom-darkweb.com/ - darknet guns drugs
名前
Granttromo
new darknet marketplaces <a href="https://heinekenmarketplacee.com/ ">Cocorico url </a> https://kingdom-darkweb-drugstore.com/ - darknet drug store
名前
Randytiz
deep web marketplaces reddit <a href="https://heinekendarkmarketplace.com/ ">dream market darknet </a> https://heinekendarkmarketplace.com/ - illegal black market
名前
TimmyMeexy
alphabay darknet market <a href="https://kingdom-onion.com/ ">best darknet market may 2023 reddit </a> https://kingdom-onion.com/ - dark web sites links
名前
Danired
currently darknet markets <a href="https://heinekenmarket-darknet.com/ ">2023 darknet market </a> https://heinekenmarket-darknet.com/ - bitcoin black market
名前
JamesseM
online black market electronics <a href="https://kingdomdrugsmarket.com/ ">darknet prices </a> https://kingdomdrugsmarket.com/ - deep web link 2023
名前
Sirket
what darknet markets are open <a href="https://heineken-darkmarketplace.com/ ">darknet market sites and how </a> https://heineken-darkwebmarket.com/ - bitcoin black market
名前
JasonGribe
Kingdom link <a href="https://darkfox-onlinedrugs.com/ ">where to find onion links </a> https://darkfox-onlinedrugs.com/ - darknet markets may 2023
名前
Baaket
cvv black market <a href="https://kingdom-dark-market.com/ ">how to access the dark web safely reddit </a> https://kingdomdarkmarketplace.com/ - best darknet market for steroids
名前
Ralphzet
archetyp market link <a href="https://kingdomdarkmarketonline.com/ ">onion seiten </a> https://kingdom-darkmarket-online.com/ - best darknet drug market 2023
名前
CharlesNuh
darknet illegal market <a href="https://heinekenmarket-url.com/ ">best current darknet market </a> https://heinekenmarketlink.com/ - reddit darknet markets list
名前
BrandonWaype
dark market links <a href="https://kingdom-online-drugs.com/ ">how to get access to darknet </a> https://kingdomonionmarket.com/ - alphabay market net
名前
Ronaldevica
pill with crown on it <a href="https://heineken-onion-darkweb.com/ ">darknet search engine url </a> https://heinekendarknetdrugstore.com/ - best darknet market 2023 reddit
名前
RichardDek
reddit best darknet market <a href="https://kingdom-onion-darkweb.com/ ">dark markets san marino </a> https://kingdom-onion-darkweb.com/ - vice city market link
名前
Geraldhopay
monkey xtc pill <a href="https://heineken-onlinedrugs.com/ ">reddit darknetmarket </a> https://heineken-drugs-online.com/ - tor2door market darknet
名前
Michaelloush
asap link <a href="https://kingdom-drugsonline.com/ ">tor markets 2023 </a> https://kingdom-drugsonline.com/ - dark web sites
名前
WilliamNaw
site onion liste <a href="https://darkfox-onion-darkweb.com/ ">legit darknet markets </a> https://kingdom-marketplace.com/ - australian dark web vendors
名前
WilliamRip
dark web prepaid cards reddit <a href="https://heineken-darknet.com/ ">dark web store </a> https://heineken-darknet.com/ - drug market
名前
Michaeltus
underground card shop <a href="https://heinekenonlinedrugs.com/ ">darknet markets wax weed </a> https://heinekenonlinedrugs.com/ - escrow dark web
名前
Stevejails
darknet black market list <a href="https://heinekenmarketurl.com/ ">dark web payment methods </a> https://heinekenurl.com/ - dumps shop
名前
Charlescob
darknet сайты список <a href="https://heinekenmarket-links.com/ ">black market buy online </a> https://heinekenmarket-links.com/ - darknet bitcoin market
名前
Robertfup
how to get on the dark web on laptop <a href="https://kingdom-onion-market.com/ ">darknet markets without login </a> https://kingdom-onion-market.com/ - buy real money
名前
DamonLat
darknet market and monero <a href="https://heinekenoniondarkmarket.com/ ">drugs on the deep web </a> https://heinekenoniondarkmarket.com/ - darknet market google
名前
RobertKix
underground card shop <a href="https://kingdomdarkweb.com/ ">versus market darknet </a> https://kingdomdarknet.com/ - dark markets uk
名前
JamesHub
darkfox link <a href="https://dark-web-heineken.com/ ">darknet markets with tobacco </a> https://dark-web-heineken.com/ - buying credit cards on dark web
名前
HaroldHot
tfmpp pills <a href="https://kingdommarket-online.com/ ">how to install deep web </a> https://kingdomdarkmarket.com/ - xanax darknet markets reddit
名前
Hanstulge
darknet drug prices <a href="https://heineken-onion.com/ ">Heineken Express url </a> https://heineken-onion.com/ - best darknet markets 2023
名前
Dannyquord
ketamine darknet market <a href="https://heineken-drugs-market.com/ ">trusted darknet markets weed </a> https://heineken-drugs-market.com/ - darknet union
名前
Brandendet
deep web links reddit <a href="https://drheinekenexpress.com/ ">darknet drugs links </a> https://drheinekenexpress.com/ - buying from darknet market with electrum
名前
Richardvak
best darknet market may 2023 reddit <a href="https://kingdommarketdarknet.com/ ">darknet escrow </a> https://kingdom-markett.com/ - tor market
名前
Tornaddib
site onion liste <a href="https://darkfox-onion-darkmarket.com/ ">deep web drug store </a> https://darkfoxdarkwebdrugstore.com/ - crypto darknet drug shop
名前
Jancal
fresh onions link <a href="https://darkfoxdarknetdrugstore.com/ ">deep dark web markets links </a> https://darkfoxdarknetdrugstore.com/ - darknet live stream
名前
Crisscunc
darknet drugs dublin <a href="https://kingdomurl.com/ ">site onion liste </a> https://kingdommarketurl.com/ - underground dumps shop
名前
Hellyzes
dark markets canada <a href="https://kingdommarket-links.com/ ">dark markets croatia </a> https://kingdommarket-darknet.com/ - dark web buy bitcoin
名前
CorryViarD
how to get to darknet market safe <a href="https://kingdomonion.com/ ">incognito url </a> https://darkmarketkingdom.com/ - link de hiden wiki
名前
FrankHuluh
best darknet market australia <a href="https://heinekendarknetmarket.com/ ">best dark net markets </a> https://heinekendarknetmarket.com/ - black market webshop
名前
Josephanarm
where to find darknet market links redit <a href="https://dark-web-kingdom.com/ ">dark markets macedonia </a> https://darkmarket-kingdom.com/ - darknet drugs guide
名前
Danielred
list of darknet drug markets <a href="https://heinekenonion.com/ ">black market webshop </a> https://darkmarketheineken.com/ - darknet wiki link
名前
ZacharyBop
best darknet marketplaces <a href="https://kingdomdarkwebdrugstore.com/ ">incognito market url </a> https://kingdom-darknet-drugstore.com/ - drug market
名前
Julianacecy
drug market <a href="https://kingdomdarkwebmarket.com/ ">drug markets dark web </a> https://kingdomdarkwebmarket.com/ - best drug darknet
名前
Wendellpog
counterfeit money dark web reddit <a href="https://heineken-online-drugs.com/ ">darknet markets 2023 reddit </a> https://heinekenonionmarket.com/ - market deep web 2023
名前
Edgarlow
darknet link drugs <a href="https://kingdom-drugs-online.com/ ">darkmarket url </a> https://kingdom-onlinedrugs.com/ - darknet onion links drugs
名前
Shanewat
darknet bank accounts <a href="https://heineken-express-onion.com/ ">crypto market darknet </a> https://heineken-express-onion.com/ - dark markets indonesia
名前
BrianFew

コメントを追加

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