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

カテゴリー

コメント

cannabis dark web <a href="https://darkmarketheineken.com/ ">buying things from darknet markets </a> https://heinekenonion.com/ - darknet markets reddit links
名前
ZacharyBop
darknet market listing <a href="https://heinekendrugsmarket.com/ ">red ferrari pills </a> https://heinekendrugsmarketplace.com/ - how to access dark web markets
名前
MichaelRaf
how to buy bitcoin for the dark web <a href="https://kingdom-drugs-online.com/ ">uncensored hidden wiki link </a> https://kingdom-onlinedrugs.com/ - buying drugs online
名前
Shanewat
cypher market url <a href="https://kingdom-darkmarket.com/ ">darkmarket url </a> https://kingdom-darkmarket.com/ - trusted darknet vendors
名前
Wendellpog
Cocorico Market darknet <a href="https://kingdom-onion.com/ ">dark web market list </a> https://darkwebkingdom.com/ - deep dot web markets
名前
Danired
incognito market url <a href="https://kingdommarket-links.com/ ">dark web store </a> https://kingdommarket-links.com/ - darknet adress
名前
CorryViarD
darknet xanax <a href="https://heinekenmarketonlinee.com/ ">darknet seiten liste </a> https://heinekenmarketonlinee.com/ - where to find onion links
名前
Patrickhuple
darknet search engine url <a href="https://heineken-express-onion.com/ ">shop online without cvv code </a> https://heineken-express-onion.com/ - darknet markets japan
名前
BrianFew
redit safe darknet markets <a href="https://heinekenmarketplace24.com/ ">dark web electronics </a> https://heinekenmarketplace24.com/ - dark web vendors
名前
Georgelouse
darknet market links reddit <a href="https://kingdom-darkmarketplace.com/ ">darknet onion markets </a> https://kingdom-darkwebmarket.com/ - dark markets switzerland
名前
JamesStaiz
reddit darknet markets 2023 <a href="https://heinekendarknet.com/ ">best darknet market for lsd </a> https://heinekendarknet.com/ - darknet drug delivery
名前
JuliusEsobe
deep sea darknet market <a href="https://darkfoxonlinedrugs.com/ ">online black market electronics </a> https://darkfoxonlinedrugs.com/ - deep web markets
名前
Davidinodo
darknet market features <a href="https://heineken-onion-darkmarket.com/ ">archetyp market url </a> https://heineken-onion-darkmarket.com/ - dark web steroids
名前
JackieDuart
tramadol dark web <a href="https://kingdommarketonlinee.com/ ">hire an assassin dark web </a> https://kingdommarketonlinee.com/ - what is a darknet drug market like
名前
SmittMef
dark markets lithuania <a href="https://heineken-darkmarket-online.com/ ">onion directory list </a> https://heinekendarkmarketonline.com/ - dark markets lithuania
名前
Randykew
dark net guide <a href="https://kingdomoniondarkmarket.com/ ">reddit darknet market deals </a> https://kingdomoniondarkweb.com/ - dark markets argentina
名前
CraigAgeni
orange sunshine lsd <a href="https://heinekendarkwebmarket.com/ ">dark net market links 2023 </a> https://heineken-darkmarket.com/ - carding dark web
名前
DonaldDic
dark markets netherlands <a href="https://kingdomdrugsonline.com/ ">counterfeit money deep web </a> https://kingdomdrugsonline.com/ - Cocorico Market darknet
名前
Davidjoisp
incognito market link <a href="https://kingdom-darkweb.com/ ">dark web sales </a> https://kingdom-darkweb.com/ - dark markets ireland
名前
Granttromo
dark net market list <a href="https://darkweb-heineken.com/ ">dark web store </a> https://darkweb-heineken.com/ - top 10 dark web url
名前
Matthewgek
dxm pills <a href="https://kingdomdrugsmarketplace.com/ ">bitcoins and darknet markets </a> https://kingdomdrugsmarket.com/ - dark net guide
名前
Sirket
what darknet market to use now <a href="https://heineken-dark-market.com/ ">darknet markets reddit </a> https://heinekendarkmarketplace.com/ - asap market darknet
名前
TimmyMeexy
best card shops <a href="https://kingdom-darkweb-drugstore.com/ ">darknet drug store </a> https://heinekenmarketplacee.com/ - deep web drug store
名前
Randytiz
deep web websites reddit <a href="https://heineken-drugs-online.com/ ">darknetlive </a> https://heineken-drugs-online.com/ - good dark web search engines
名前
Michaelloush
dark market sites <a href="https://heineken-markett.com/ ">what is a darknet drug market like </a> https://heineken-markett.com/ - what is the darknet market
名前
JamesseM
black market url deep web <a href="https://heineken-darkmarketplace.com/ ">new darknet markets </a> https://heineken-darkwebmarket.com/ - 2023 darknet markets
名前
JasonGribe
darknet market black <a href="https://kingdommarketplacee.com/ ">how to search the dark web reddit </a> https://kingdommarketplacee.com/ - the darknet market reddit
名前
Baaket
cypher market link <a href="https://heineken-onion-darkweb.com/ ">darknet paypal accounts </a> https://heinekendarknetdrugstore.com/ - onion seiten
名前
RichardDek
darknet onion markets <a href="https://kingdom-darkmarket-online.com/ ">dark web website links </a> https://kingdom-darkmarket-online.com/ - deep web trading
名前
CharlesNuh
darknet market 2023 reddit <a href="https://kingdom-dark-market.com/ ">dark market </a> https://kingdomdarkmarketplace.com/ - best darknet market for weed uk
名前
Ralphzet
darknet onion links drugs <a href="https://kingdom-marketplace.com/ ">darknet market search engine </a> https://darkfox-onion-darkweb.com/ - safe darknet markets
名前
WilliamRip
darknet market place search <a href="https://kingdomdarknetmarket.com/ ">dark web site list </a> https://kingdomdarknetmarket.com/ - where to find darknet market links
名前
Crisscunc
deep web directory onion <a href="https://kingdom-drugs-market.com/ ">deep web onion url </a> https://kingdom-drugs-market.com/ - black market alternative
名前
WilliamNaw
reddit darknet market how to <a href="https://kingdom-online-drugs.com/ ">incognito market </a> https://kingdom-online-drugs.com/ - dark markets hungary
名前
Ronaldevica
wiki darknet market <a href="https://heinekenoniondarkweb.com/ ">dark web markets reddit </a> https://heinekenoniondarkweb.com/ - best darknet gun market
名前
RobertKix
dark markets <a href="https://heinekenmarket-url.com/ ">alphabay url </a> https://heinekenmarketlink.com/ - dark web address list
名前
BrandonWaype
darknet list <a href="https://heinekendrugsonline.com/ ">dark markets croatia </a> https://heinekenonlinedrugs.com/ - incognito market link
名前
Stevejails
reddit darknet market 2023 <a href="https://heineken-darkweb.com/ ">incognito market </a> https://heineken-darkweb.com/ - dark markets usa
名前
Michaeltus
darknet in person drug sales <a href="https://kingdomdarknetdrugstore.com/ ">darknet illegal market </a> https://kingdom-onion-darkweb.com/ - blue lady e pill
名前
Geraldhopay
how to get on the dark web <a href="https://heinekenurl.com/ ">darknet gun market </a> https://heinekenurl.com/ - r darknet market
名前
Charlescob
dark markets brazil <a href="https://darkfox-onion-darkmarket.com/ ">best darknet market for psychedelics </a> https://darkfox-onion-darkmarket.com/ - how to anonymously use darknet markets
名前
Jancal
cannabis dark web <a href="https://kingdom-markett.com/ ">monkey x pill </a> https://kingdommarketdarknet.com/ - dark net market list reddit
名前
Tornaddib
darknet market list links <a href="https://darkmarket-kingdom.com/ ">dark markets russia </a> https://darkmarket-kingdom.com/ - darknet adressen
名前
Danielred
which darknet markets accept zcash <a href="https://kingdomdarkmarket.com/ ">which darknet market are still up </a> https://kingdomdarkmarket.com/ - darknet websites
名前
Hanstulge
darknet market lists <a href="https://heinekendarkmarket.com/ ">access darknet markets </a> https://heinekendarkmarket.com/ - credit card black market websites
名前
DavidDes
darknet search <a href="https://heinekenmarket-link.com/ ">deep web links reddit 2023 </a> https://heinekenmarket-link.com/ - darknet drugs sites
名前
Robertfup
darknet market vendors search <a href="https://heineken-drugs-market.com/ ">dark web drug markets </a> https://heineken-drugsonline.com/ - dark web search tool
名前
Brandendet
darknet market links buy ssn <a href="https://kingdomdarknet.com/ ">black market url deep web </a> https://kingdomdarkweb.com/ - darknet market lists
名前
JamesHub
dark markets australia <a href="https://dark-web-heineken.com/ ">bohemia market darknet </a> https://dark-web-heineken.com/ - list of darknet drug markets
名前
HaroldHot
cp links dark web <a href="https://heineken-online-drugs.com/ ">reliable darknet markets lsd </a> https://heinekenonionmarket.com/ - uk darknet markets
名前
Edgarlow

コメントを追加

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