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

カテゴリー

コメント

reddit darknet reviews <a href="https://dark-web-heineken.com/ ">guide to darknet markets </a> https://darkmarket-heineken.com/ - dumps shop
名前
HaroldHot
dark market 2023 <a href="https://heinekenexpressonion.com/ ">underground market place darknet </a> https://heinekenexpressonion.com/ - darknet drugs sales
名前
Dannyquord
deep web websites reddit <a href="https://kingdommarket-online.com/ ">dark web drugs australia </a> https://kingdomdarkmarket.com/ - phenylethylamine
名前
Hanstulge
dark web sites xxx <a href="https://heinekennexpress.com/ ">which darknet markets are up </a> https://heinekennexpress.com/ - darknet drugs sites
名前
Richardvak
how to buy drugs dark web <a href="https://kingdommarketplacee.com/ ">darknet market alaska </a> https://darkfox-onlinedrugs.com/ - darknet drug market list
名前
Baaket
best working darknet market 2023 <a href="https://heineken-drugs-market.com/ ">darkweb market </a> https://heineken-drugs-market.com/ - deep web shopping site
名前
Brandendet
Kingdom url <a href="https://darkfox-onion-darkweb.com/ ">darkfox link </a> https://kingdom-marketplace.com/ - the real deal market darknet
名前
WilliamRip
best website to buy cc <a href="https://kingdom-onion.com/ ">dark markets albania </a> https://kingdom-onion.com/ - dark websites reddit
名前
Danired
what darknet markets still work <a href="https://darkmarketkingdom.com/ ">price of black market drugs </a> https://darkmarketkingdom.com/ - dark web onion markets
名前
FrankHuluh
ruonion <a href="https://kingdom-onion-darkweb.com/ ">how to create a darknet market </a> https://kingdom-onion-darkweb.com/ - new darknet markets 2023
名前
Geraldhopay
dark web links <a href="https://heinekenmarketdarknet.com/ ">dark web hitmen </a> https://heinekenmarketdarknet.com/ - darknet market script
名前
Josephanarm
dark web links adult <a href="https://kingdommarketlink.com/ ">reddit darknet markets links </a> - reddit darknet market noobs
名前
ADElugh
darkmarket url <a href="https://heinekenonionmarket.com/ ">the onion directory </a> https://heineken-online-drugs.com/ - best darknet market may 2023 reddit
名前
Edgarlow
darknet market reddit <a href="https://darkwebheineken.com/ ">list of darknet markets 2023 </a> https://heineken-express-onion.com/ - darknet market forum
名前
BrianFew
updated darknet market list <a href="https://heineken-onlinedrugs.com/ ">exploit market darknet </a> https://heineken-drugs-online.com/ - list of dark net markets
名前
Michaelloush
best darknet market for steroids <a href="https://heinekenonion.com/ ">counterfeit euro deep web </a> https://darkmarketheineken.com/ - the best onion sites
名前
ZacharyBop
guide to using darknet markets <a href="https://kingdom-darkmarket.com/ ">darknet market black </a> https://kingdomdarkwebmarket.com/ - darknet markets deepdotweb
名前
Wendellpog
best darknet drug market 2023 <a href="https://kingdom-onlinedrugs.com/ ">darknet search engine </a> https://kingdom-drugs-online.com/ - dark web uk
名前
Shanewat
dark markets united kingdom <a href="https://heinekenn-express.com/ ">ethereum darknet markets </a> https://heinekenmarketonlinee.com/ - darknet market busts
名前
Patrickhuple
dark web store <a href="https://heinekendrugsmarketplace.com/ ">darknet markets working links </a> https://heinekendrugsmarketplace.com/ - berlin telegram group drugs
名前
MichaelRaf
deep web search engine 2023 <a href="https://heinekendarkwebdrugstore.com/ ">how to anonymously use darknet markets </a> https://heinekendarkwebdrugstore.com/ - darknet market links safe
名前
HectorDer
darknet drug dealer <a href="https://heinekenmarketplace24.com/ ">drug markets onion </a> https://heineken-marketplace.com/ - link darknet market
名前
Georgelouse
urls for darknet markets <a href="https://kingdom-onion-darkmarket.com/ ">darknet dream market link </a> https://kingdom-onion-market.com/ - darkweb sites reddit
名前
DamonLat
open darknet markets <a href="https://kingdom-darkwebmarket.com/ ">darknet market adderall </a> https://kingdom-darkwebmarket.com/ - links the hidden wiki
名前
JamesStaiz
cypher link <a href="https://drkingdommarket.com/ ">darknet market links </a> https://drkingdommarket.com/ - darknet wiki link
名前
SmittMef
dark web market links <a href="https://heineken-darkmarket-online.com/ ">site darknet fermГ© </a> https://heinekendarkmarketonline.com/ - deep web directory onion
名前
Randykew
tor2door market url <a href="https://kingdomdrugsonline.com/ ">crypto market darknet </a> https://kingdomdrugsonline.com/ - reddit darknet market list
名前
Davidjoisp
how to buy bitcoin for the dark web <a href="https://darkweb-heineken.com/ ">dot onion websites </a> https://dark-market-heineken.com/ - darknet drug market url
名前
Matthewgek
deep web search engine url <a href="https://kingdomoniondarkmarket.com/ ">crypto darknet drug shop </a> https://kingdomoniondarkweb.com/ - alpha market url
名前
CraigAgeni
dark markets mexico <a href="https://heinekendarkwebmarket.com/ ">lsd drug wiki </a> https://heineken-darkmarket.com/ - darknet market busts
名前
DonaldDic
dark markets malta <a href="https://kingdom-darknet.com/ ">darknet market listing </a> https://kingdom-darknet.com/ - dark web step by step
名前
Granttromo
incognito market <a href="https://heineken-onion-market.com/ ">how to buy drugs on darknet </a> https://heineken-onion-market.com/ - alphabay darknet market
名前
JackieDuart
darknet markets list reddit <a href="https://heinekenmarketplacee.com/ ">darknet steroid markets </a> https://kingdom-darkweb-drugstore.com/ - darknet market google
名前
Randytiz
darknet search <a href="https://heinekenmarket-darknet.com/ ">black market net </a> https://heinekenmarket-darknet.com/ - marijuana dark web
名前
JamesseM
counterfeit money dark web reddit <a href="https://kingdomdarkwebdrugstore.com/ ">darknet market thc oil </a> https://kingdom-darknet-drugstore.com/ - archetyp market link
名前
Julianacecy
deep web weed prices <a href="https://kingdomdrugsmarket.com/ ">dark markets new zealand </a> https://kingdomdrugsmarketplace.com/ - search darknet markets
名前
Sirket
dbol steroid pills <a href="https://heineken-darkmarketplace.com/ ">darknet vendor reviews </a> https://heineken-darkwebmarket.com/ - list of darknet drug markets
名前
JasonGribe
tor2door market link <a href="https://kingdomdarkmarketplace.com/ ">darknet drugs sales </a> https://kingdomdarkmarketplace.com/ - darknet markets florida
名前
Ralphzet
darknet markets fake id <a href="https://darkmarket-kingdom.com/ ">Abacus link </a> https://dark-web-kingdom.com/ - dark markets serbia
名前
Danielred
where to find onion links <a href="https://heinekenmarketlink.com/ ">darknet markets 2023 reddit </a> https://heinekenmarketlink.com/ - dot onion websites
名前
BrandonWaype
buying things from darknet markets <a href="https://kingdom-online-drugs.com/ ">best dark web counterfeit money </a> https://kingdomonionmarket.com/ - dark web payment methods
名前
Ronaldevica
darknet market <a href="https://kingdom-darkmarket-online.com/ ">top ten dark web sites </a> https://kingdomdarkmarketonline.com/ - versus market darknet
名前
CharlesNuh
vice city market darknet <a href="https://heinekendarknetdrugstore.com/ ">the onion directory </a> https://heineken-onion-darkweb.com/ - darknet market comparison chart
名前
RichardDek
dark chart <a href="https://darkfoxonlinedrugs.com/ ">working darknet markets 2023 </a> https://darkfoxonlinedrugs.com/ - deep net websites
名前
Davidinodo
dark web drugs nz <a href="https://kingdommarketurl.com/ ">guide to darknet markets </a> https://kingdommarketurl.com/ - darknet links markets
名前
Hellyzes
deep dot web markets <a href="https://kingdommarket-darknet.com/ ">darknet drugs 2023 </a> https://kingdommarket-darknet.com/ - darknet bitcoin market
名前
CorryViarD
drugs dark web price <a href="https://kingdom-drugsonline.com/ ">dark markets turkey </a> https://kingdom-drugsonline.com/ - darknet market url list
名前
WilliamNaw
tor marketplaces <a href="https://heineken-darkweb.com/ ">best fraud market darknet </a> https://heineken-darknet.com/ - how to shop on dark web
名前
Michaeltus
how to browse the dark web reddit <a href="https://heinekenonlinedrugs.com/ ">best darknet market reddit 2023 </a> https://heinekendrugsonline.com/ - dark markets denmark
名前
Stevejails
dark markets spain <a href="https://heinekenmarketurl.com/ ">deep web markets </a> https://heinekenurl.com/ - darknet drugs sales
名前
Charlescob

コメントを追加

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