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

カテゴリー

コメント

Kingdom Market <a href="https://heineken-express-onion.com/ ">dark web prepaid cards reddit </a> https://darkwebheineken.com/ - best darknet market for heroin
名前
BrianFew
grey market darknet <a href="https://kingdom-darkmarket.com/ ">Abacus link </a> https://kingdomdarkwebmarket.com/ - drug markets dark web
名前
Wendellpog
deep web markets <a href="https://kingdom-drugs-online.com/ ">darknet market steroids </a> https://kingdom-drugs-online.com/ - dark market 2023
名前
Shanewat
dark web market reviews <a href="https://heinekenn-express.com/ ">dark markets china </a> https://heinekenn-express.com/ - Kingdom url
名前
Patrickhuple
reddit darknet market how to <a href="https://heineken-marketplace.com/ ">uncensored deep web </a> https://heineken-marketplace.com/ - dark markets chile
名前
Georgelouse
most reliable darknet markets <a href="https://heinekendrugsmarket.com/ ">australian dark web vendors </a> https://heinekendrugsmarket.com/ - tor markets
名前
MichaelRaf
dark web store <a href="https://drkingdommarket.com/ ">tor search onion link </a> https://drkingdommarket.com/ - darknet market news
名前
SmittMef
dark web sales <a href="https://dark-market-heineken.com/ ">darknet market script </a> https://darkweb-heineken.com/ - incognito market url
名前
Matthewgek
wiki sticks drugs <a href="https://heineken-darkmarket-online.com/ ">deep net links </a> https://heineken-darkmarket-online.com/ - best darknet market australia
名前
Randykew
reddit onion list <a href="https://kingdom-darkwebmarket.com/ ">deep web drug links </a> https://kingdom-darkwebmarket.com/ - what darknet markets are still open
名前
JamesStaiz
dark markets slovenia <a href="https://kingdom-darkweb.com/ ">australian darknet markets </a> https://kingdom-darkweb.com/ - dark markets russia
名前
Granttromo
trusted darknet markets <a href="https://heinekendarkwebdrugstore.com/ ">currently darknet markets </a> https://heineken-darknet-drugstore.com/ - darknet markets list
名前
HectorDer
bitcoin cash darknet markets <a href="https://heineken-darkmarket.com/ ">dark web directory </a> https://heinekendarkwebmarket.com/ - dark markets slovenia
名前
DonaldDic
working darknet markets <a href="https://dark-web-kingdom.com/ ">black market alternative </a> https://darkmarket-kingdom.com/ - darknet market superlist
名前
Danielred
darknet drugs safe <a href="https://kingdomonlinedrugs.com/ ">fake id onion </a> https://kingdomonlinedrugs.com/ - onion links 2023
名前
Davidjoisp
darknet market <a href="https://kingdomoniondarkmarket.com/ ">darknet markets still up </a> https://kingdomoniondarkweb.com/ - how to get on darknet market
名前
CraigAgeni
darknet drugs url <a href="https://kingdommarketurl.com/ ">dark web step by step </a> https://kingdomurl.com/ - darknet market steroids
名前
Hellyzes
top ten deep web <a href="https://kingdommarket-darknet.com/ ">darkmarket url </a> https://kingdommarket-darknet.com/ - Cocorico Market darknet
名前
CorryViarD
darknet drug delivery <a href="https://darkfox-onion-darkweb.com/ ">dnm market </a> https://kingdom-marketplace.com/ - the real deal market darknet
名前
WilliamRip
drug market darknet <a href="https://darkfoxonionmarket.com/ ">dark web links reddit </a> https://darkfoxonlinedrugs.com/ - blockchain darknet markets
名前
Davidinodo
darknet best drugs <a href="https://kingdom-darkweb-drugstore.com/ ">darknet illicit drugs </a> https://heinekenmarketplacee.com/ - darknet links 2023 drugs
名前
Randytiz
darknet market comparison <a href="https://heineken-markett.com/ ">vice city darknet market </a> https://heineken-markett.com/ - Cocorico Market link
名前
JamesseM
how to get access to darknet <a href="https://heineken-onion-market.com/ ">best tor marketplaces </a> https://heineken-onion-darkmarket.com/ - how to use onion sites
名前
JackieDuart
tor darknet sites <a href="https://heineken-darkwebmarket.com/ ">how to anonymously use darknet markets </a> https://heineken-darkwebmarket.com/ - deep web search engines 2023
名前
JasonGribe
darknet markets may 2023 <a href="https://kingdomdrugsmarketplace.com/ ">darknet drugs reddit </a> https://kingdomdrugsmarket.com/ - updated darknet market list
名前
Sirket
darknet drug links <a href="https://heinekendrugsonline.com/ ">versus project market url </a> https://heinekenonlinedrugs.com/ - biggest darknet market
名前
Stevejails
darknet market links reddit <a href="https://dark-market-kingdom.com/ ">Cocorico Market url </a> https://darkweb-kingdom.com/ - dark web market links
名前
Teddred
dark web hitman for hire <a href="https://kingdomdarkmarketplace.com/ ">best darknet market reddit 2023 </a> https://kingdom-dark-market.com/ - Kingdom Market link
名前
Ralphzet
onion links for deep web <a href="https://kingdom-onion-darkweb.com/ ">dark web address list </a> https://kingdom-onion-darkweb.com/ - the dark web links 2023
名前
Geraldhopay
biggest darknet markets 2023 <a href="https://kingdomdarkmarketonline.com/ ">onion links 2023 </a> https://kingdomdarkmarketonline.com/ - top darknet markets
名前
CharlesNuh
underground market online <a href="https://heinekenmarketlink.com/ ">outlaw darknet market url </a> https://heinekenmarketlink.com/ - dark markets ukraine
名前
BrandonWaype
archetyp market <a href="https://heinekenoniondarkweb.com/ ">cypher link </a> https://heinekenoniondarkmarket.com/ - darknet markets dread
名前
RobertKix
onion directory list <a href="https://heineken-darknet.com/ ">black market website legit </a> https://heineken-darknet.com/ - dark web prepaid cards reddit
名前
Michaeltus
how to access deep web safely reddit <a href="https://heineken-drugs-online.com/ ">xanax darknet markets reddit </a> https://heineken-onlinedrugs.com/ - how to access the dark web through tor
名前
Michaelloush
darknet market security <a href="https://heineken-online-drugs.com/ ">darknet adressen </a> https://heineken-online-drugs.com/ - black market website legit
名前
Edgarlow
deep web addresses onion <a href="https://heinekendarknetdrugstore.com/ ">darknet markets noob </a> https://heinekendarknetdrugstore.com/ - reliable darknet markets lsd
名前
RichardDek
incognito market darknet <a href="https://heinekenmarketurl.com/ ">best darknet drug sites </a> https://heinekenmarketurl.com/ - dark markets austria
名前
Charlescob
drugs dark web reddit <a href="https://kingdommarketplacee.com/ ">french deep web link </a> https://darkfox-onlinedrugs.com/ - vice city darknet market
名前
Baaket
dark markets romania <a href="https://kingdom-drugsonline.com/ ">deep website search engine </a> https://kingdom-drugs-market.com/ - free deep web links
名前
WilliamNaw
best darknet market reddit <a href="https://darkfoxdarkwebdrugstore.com/ ">darknet websites drugs </a> https://darkfoxdarkwebdrugstore.com/ - darknet markets japan
名前
Jancal
archetyp url <a href="https://kingdom-online-drugs.com/ ">dark web poison </a> https://kingdom-online-drugs.com/ - darknet markets may 2023
名前
Ronaldevica
darknet markets onion address <a href="https://kingdom-markett.com/ ">live dark web </a> https://kingdom-markett.com/ - dark chart
名前
Tornaddib
alphabay darknet market <a href="https://kingdom-onion-darkmarket.com/ ">reliable darknet markets </a> https://kingdom-onion-market.com/ - best darknet market for weed 2023
名前
DamonLat
drugs dark web reddit <a href="https://heinekenmarket-links.com/ ">counterfeit money dark web reddit </a> https://heinekenmarket-links.com/ - versus project market link
名前
Robertfup
dn market <a href="https://kingdomdarknet.com/ ">cannabis dark web </a> https://kingdomdarkweb.com/ - new darknet markets 2023
名前
JamesHub
online black market uk <a href="https://dark-web-heineken.com/ ">dark web link </a> https://dark-web-heineken.com/ - dark markets ecuador
名前
HaroldHot
orange sunshine pill <a href="https://kingdom-onion.com/ ">top dark net markets </a> https://darkwebkingdom.com/ - drugs darknet vendors
名前
Danired
online black market uk <a href="https://heinekenexpressonion.com/ ">darknet websites wiki </a> https://heineken-onion.com/ - dark web search engines link
名前
Dannyquord
darknet escrow <a href="https://kingdomdarkmarket.com/ ">darknet drug delivery </a> https://kingdommarket-online.com/ - drugs onion
名前
Hanstulge
dark net markets <a href="https://drheinekenexpress.com/ ">deep web shopping site </a> https://heinekennexpress.com/ - dark web website links
名前
Richardvak

コメントを追加

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