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

カテゴリー

コメント

legit darknet markets 2023 <a href="https://dark-web-heineken.com/ ">superman pills mg </a> https://dark-web-heineken.com/ - how to buy from the darknet markets lsd
名前
HaroldHot
online black market electronics <a href="https://heineken-onion.com/ ">deep website search engine </a> https://heinekenexpressonion.com/ - nike jordan pill
名前
Dannyquord
dark markets canada <a href="https://kingdommarketplacee.com/ ">darknet adressen </a> https://darkfox-onlinedrugs.com/ - dark web drug markets
名前
Baaket
dark web onion markets <a href="https://kingdom-onion-darkmarket.com/ ">steroid market darknet </a> https://kingdom-onion-market.com/ - reddit darknet market links
名前
DamonLat
deep web deb <a href="https://kingdomdarkmarket.com/ ">legit darknet markets </a> https://kingdommarket-online.com/ - darknet market reddits
名前
Hanstulge
site onion liste <a href="https://heinekennexpress.com/ ">wiki darknet market </a> https://drheinekenexpress.com/ - darknet stock market
名前
Richardvak
alphabay url <a href="https://kingdommarket-url.com/ ">dark markets france </a> - tor darknet
名前
ADElugh
versus project darknet market <a href="https://darkmarketkingdom.com/ ">the best onion sites </a> https://darkmarketkingdom.com/ - dark markets india
名前
FrankHuluh
dark markets austria <a href="https://darkfoxdarknetdrugstore.com/ ">updated darknet market list </a> https://darkfoxdarknetdrugstore.com/ - darknet drug market url
名前
Crisscunc
versus project darknet market <a href="https://heinekenmarketdarknet.com/ ">onion marketplace drugs </a> https://heinekendarknetmarket.com/ - darknet markets dread
名前
Josephanarm
dark markets belgium <a href="https://heinekenonion.com/ ">tor darknet sites </a> https://darkmarketheineken.com/ - darknet market stats
名前
ZacharyBop
reddit darknet market uk <a href="https://kingdomdarkwebmarket.com/ ">darknet drugs shipping </a> https://kingdomdarkwebmarket.com/ - dark web marketplace
名前
Wendellpog
deep web drug links <a href="https://darkwebheineken.com/ ">dark markets czech republic </a> https://heineken-express-onion.com/ - darknet market status
名前
BrianFew
darkmarket website <a href="https://heineken-drugsonline.com/ ">alphabay market url </a> https://heineken-drugs-market.com/ - darknet markets reddit
名前
Brandendet
best darknet market for guns <a href="https://kingdom-onion.com/ ">brick market </a> https://darkwebkingdom.com/ - buying darknet drugs
名前
Danired
deep web link 2023 <a href="https://heinekendarkweb.com/ ">ruonion </a> https://heinekendarknet.com/ - best websites dark web
名前
JuliusEsobe
Heineken Express Market <a href="https://heinekendarkmarket.com/ ">best fraud market darknet </a> https://heinekenmarket-online.com/ - trusted darknet markets
名前
DavidDes
how to buy from darknet <a href="https://kingdom-drugs-online.com/ ">blockchain darknet markets </a> https://kingdom-drugs-online.com/ - darknet drug trafficking
名前
Shanewat
black market deep <a href="https://heinekenmarketonlinee.com/ ">onion deep web wiki </a> https://heinekenmarketonlinee.com/ - dark markets new zealand
名前
Patrickhuple
darknet black market sites <a href="https://kingdom-darknet-drugstore.com/ ">best darknet market drugs </a> https://kingdom-darknet-drugstore.com/ - darknet drugs sales
名前
Julianacecy
grey market drugs <a href="https://heinekenmarketplace24.com/ ">darknet market links buy ssn </a> https://heinekenmarketplace24.com/ - incognito market link
名前
Georgelouse
online black market uk <a href="https://heinekendrugsmarket.com/ ">dark markets united kingdom </a> https://heinekendrugsmarketplace.com/ - deep web cc dumps
名前
MichaelRaf
darknet market guide <a href="https://drkingdommarket.com/ ">dark web steroids </a> https://drkingdommarket.com/ - darkweb marketplace
名前
SmittMef
drug markets onion <a href="https://heinekendarkmarketonline.com/ ">Abacus darknet Market </a> https://heineken-darkmarket-online.com/ - dark web link
名前
Randykew
blue lady e pill <a href="https://dark-market-heineken.com/ ">onion directory list </a> https://darkweb-heineken.com/ - drugs on darknet
名前
Matthewgek
darknet market package <a href="https://kingdommarket-links.com/ ">best black market websites </a> https://kingdommarket-darknet.com/ - australian darknet markets
名前
CorryViarD
where to find darknet market links <a href="https://kingdommarketurl.com/ ">best darknet markets reddit </a> https://kingdomurl.com/ - counterfeit money onion
名前
Hellyzes
deep onion links <a href="https://kingdom-darkmarketplace.com/ ">darknet market pills vendor </a> https://kingdom-darkmarketplace.com/ - asap market url
名前
JamesStaiz
russian anonymous marketplace <a href="https://heinekendarkmarketplace.com/ ">i2p darknet markets </a> https://heineken-dark-market.com/ - buying drugs online
名前
TimmyMeexy
darknet new market link <a href="https://kingdom-darknet.com/ ">darkmarket url </a> https://kingdom-darkweb.com/ - top onion links
名前
Granttromo
dark markets san marino <a href="https://heinekendarkwebdrugstore.com/ ">safe list of darknet market links </a> https://heineken-darknet-drugstore.com/ - darknet market listing
名前
HectorDer
updated darknet market list <a href="https://heinekendarkwebmarket.com/ ">darknet reddit market </a> https://heinekendarkwebmarket.com/ - darknet markets list reddit
名前
DonaldDic
how to buy bitcoin and use on dark web <a href="https://kingdomdrugsonline.com/ ">dark markets slovakia </a> https://kingdomdrugsonline.com/ - darknet link drugs
名前
Davidjoisp
darknet markets address <a href="https://kingdomoniondarkweb.com/ ">darknet market script </a> https://kingdomoniondarkweb.com/ - best dark web marketplaces 2023
名前
CraigAgeni
black market deep <a href="https://kingdom-darkweb-drugstore.com/ ">darknet market alternatives </a> https://heinekenmarketplacee.com/ - darknet search engine url
名前
Randytiz
darknet market bible <a href="https://heinekenmarket-darknet.com/ ">dark web live </a> https://heinekenmarket-darknet.com/ - reddit darknet market list 2023
名前
JamesseM
how to buy from darknet markets <a href="https://heineken-darkwebmarket.com/ ">dark market url </a> https://heineken-darkwebmarket.com/ - incognito market darknet
名前
JasonGribe
darknet drugs sites <a href="https://heineken-onion-market.com/ ">darknet drug store </a> https://heineken-onion-market.com/ - reddit darknet markets noobs
名前
JackieDuart
darknet markets wax weed <a href="https://kingdomdrugsmarket.com/ ">darknet market </a> https://kingdomdrugsmarketplace.com/ - dark markets romania
名前
Sirket
dark web sites for drugs <a href="https://heinekendrugsonline.com/ ">best darknet market 2023 reddit </a> https://heinekendrugsonline.com/ - current list of darknet markets
名前
Stevejails
duckduckgo onion site <a href="https://kingdom-marketplace.com/ ">onion deep web wiki </a> https://kingdom-marketplace.com/ - incognito link
名前
WilliamRip
darknet markets with tobacco <a href="https://heineken-online-drugs.com/ ">black market bank account </a> https://heineken-online-drugs.com/ - darknet steroid markets
名前
Edgarlow
darknet markets norge <a href="https://kingdom-dark-market.com/ ">brick market </a> https://kingdomdarkmarketplace.com/ - most reliable darknet markets
名前
Ralphzet
market onion <a href="https://heinekenmarket-url.com/ ">darknet market oz </a> https://heinekenmarket-url.com/ - marijuana dark web
名前
BrandonWaype
darknet markets <a href="https://darkfoxonlinedrugs.com/ ">cheap darknet websites dor drugs </a> https://darkfoxonlinedrugs.com/ - legit darknet markets
名前
Davidinodo
assassination market darknet <a href="https://kingdomdarkmarketonline.com/ ">deep net websites </a> https://kingdomdarkmarketonline.com/ - darknet market wikia
名前
CharlesNuh
dark markets spain <a href="https://darkmarket-kingdom.com/ ">buy bank accounts darknet </a> https://dark-web-kingdom.com/ - darkweb market
名前
Danielred
brucelean darknet market <a href="https://heinekenurl.com/ ">how to buy bitcoin for the dark web </a> https://heinekenurl.com/ - trusted darknet markets weed
名前
Charlescob
dark web weed <a href="https://heineken-darknet.com/ ">deep web link 2023 </a> https://heineken-darkweb.com/ - dark markets serbia
名前
Michaeltus
Cocorico Market darknet <a href="https://darkfoxdarkwebdrugstore.com/ ">darknet market links buy ssn </a> https://darkfox-onion-darkmarket.com/ - list of darknet drug markets
名前
Jancal

コメントを追加

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