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

カテゴリー

コメント

dark markets canada <a href="https://heinekendrugsonline.com/ ">deep dot web replacement </a> https://heinekendrugsonline.com/ - market onion
名前
Stevejails
deep cp links <a href="https://kingdomdrugsmarket.com/ ">onion links for deep web </a> https://kingdomdrugsmarket.com/ - black market websites tor
名前
Sirket
darknet paypal accounts <a href="https://kingdom-dark-market.com/ ">blacknet drugs </a> https://kingdom-dark-market.com/ - darknet market status
名前
Ralphzet
darknet market noobs reddit <a href="https://kingdom-marketplace.com/ ">dark web drugs ireland </a> https://kingdom-marketplace.com/ - ketamine darknet market
名前
WilliamRip
black market website legit <a href="https://heinekenmarket-url.com/ ">dark web links market </a> https://heinekenmarket-url.com/ - reddit darknet market deals
名前
BrandonWaype
duckduckgo onion site <a href="https://heineken-drugs-online.com/ ">darknet marketplace drugs </a> https://heineken-onlinedrugs.com/ - dark markets andorra
名前
Michaelloush
dark market reddit <a href="https://heinekenoniondarkmarket.com/ ">deep web software market </a> https://heinekenoniondarkweb.com/ - darkmarket url
名前
RobertKix
credit card dumps dark web <a href="https://kingdom-darkmarket-online.com/ ">darknet drug markets </a> https://kingdom-darkmarket-online.com/ - lsd drug wiki
名前
CharlesNuh
alphabay link <a href="https://darkfoxdarkwebdrugstore.com/ ">deep web cc shop </a> https://darkfox-onion-darkmarket.com/ - drugs on the deep web
名前
Jancal
best darknet market uk <a href="https://heinekenurl.com/ ">reddit best darknet market </a> https://heinekenurl.com/ - Cocorico Market url
名前
Charlescob
darkfox link <a href="https://heineken-darkweb.com/ ">dark markets san marino </a> https://heineken-darknet.com/ - darknet market controlled delivery
名前
Michaeltus
bohemia link <a href="https://heinekendarknetdrugstore.com/ ">onion sex shop </a> https://heineken-onion-darkweb.com/ - darknet cannabis markets
名前
RichardDek
darknet market reviews <a href="https://kingdom-drugsonline.com/ ">Abacus Market </a> https://kingdom-drugsonline.com/ - onion linkek
名前
WilliamNaw
best darknet market urs <a href="https://kingdommarketdarknet.com/ ">dark markets bolivia </a> https://kingdom-markett.com/ - darknet live stream
名前
Tornaddib
underground black market website <a href="https://kingdom-online-drugs.com/ ">how to use deep web on pc </a> https://kingdom-online-drugs.com/ - dark web market list
名前
Ronaldevica
monero darknet market <a href="https://kingdomdarkweb.com/ ">black market deep </a> https://kingdomdarknet.com/ - black market website
名前
JamesHub
trusted darknet vendors <a href="https://darkfoxonionmarket.com/ ">free deep web links </a> https://darkfoxonionmarket.com/ - darknet buy drugs
名前
Davidinodo
buying credit cards on dark web <a href="https://heinekenexpressonion.com/ ">darknet markets working links </a> https://heinekenexpressonion.com/ - darknet market buying mdma usa
名前
Dannyquord
buying drugs on the darknet <a href="https://dark-web-heineken.com/ ">uk darknet markets </a> https://darkmarket-heineken.com/ - list of darknet drug markets
名前
HaroldHot
active darknetmarkets <a href="https://heinekenmarket-link.com/ ">current list of darknet markets </a> https://heinekenmarket-link.com/ - the darknet markets
名前
Robertfup
darknet markets lsd-25 2023 <a href="https://kingdom-onion-darkweb.com/ ">versus market </a> https://kingdomdarknetdrugstore.com/ - reddit darknet market deals
名前
Geraldhopay
onion seiten 2023 <a href="https://dark-web-kingdom.com/ ">darknet cannabis markets </a> https://dark-web-kingdom.com/ - darknet market noobs guide
名前
Danielred
price of black market drugs <a href="https://kingdommarketlink.com/ ">tramadol dark web </a> - weed darknet market
名前
ADElugh
dark market sites <a href="https://kingdommarket-online.com/ ">archetyp market darknet </a> https://kingdommarket-online.com/ - we amsterdam
名前
Hanstulge
darknet drug vendors <a href="https://kingdomonion.com/ ">dark web buy credit cards </a> https://kingdomonion.com/ - dark web links adult
名前
FrankHuluh
deep sea darknet market <a href="https://drheinekenexpress.com/ ">darknet list </a> https://heinekennexpress.com/ - dark markets luxembourg
名前
Richardvak
best darknet markets <a href="https://kingdomdarknetmarket.com/ ">darknet selling drugs </a> https://kingdomdarknetmarket.com/ - dark markets norway
名前
Crisscunc
dark markets netherlands <a href="https://heinekenonion.com/ ">dark markets france </a> https://darkmarketheineken.com/ - shop online without cvv code
名前
ZacharyBop
dark markets india <a href="https://kingdom-darkmarket.com/ ">archetyp darknet market </a> https://kingdom-darkmarket.com/ - how to anonymously use darknet markets
名前
Wendellpog
darknet drug market url <a href="https://heineken-express-onion.com/ ">legit darknet markets 2023 </a> https://darkwebheineken.com/ - dark web step by step
名前
BrianFew
darknet escrow <a href="https://heinekendarknetmarket.com/ ">versus darknet market </a> https://heinekenmarketdarknet.com/ - Cocorico url
名前
Josephanarm
site darknet onion <a href="https://heineken-drugsonline.com/ ">new alphabay darknet market </a> https://heineken-drugs-market.com/ - dark markets turkey
名前
Brandendet
<a href="https://k-tv.ru/">k-tv.ru</a>
名前
otzzclgy
deep web drug url <a href="https://kingdommarketplacee.com/ ">bohemia market link </a> https://darkfox-onlinedrugs.com/ - dark websites reddit
名前
Baaket
how to pay with bitcoin on dark web <a href="https://darkfoxonionmarket.com/ ">darknet drugs australia </a> https://darkfoxonlinedrugs.com/ - deep web marketplaces reddit
名前
Davidven
tor2door darknet market <a href="https://kingdom-marketplace.com/ ">black market online </a> https://kingdom-marketplace.com/ - Cocorico Market
名前
Jeromesob
weed darknet market <a href="https://darkfoxdarkwebdrugstore.com/ ">dark web market </a> https://darkfoxdarkwebdrugstore.com/ - darknet markets ranked 2023
名前
AlbertGlice
why should i be accepted into college essay <a href="https://typemyessaystudent.com/">type essay</a> ithaca college essay
名前
antisa
drugs on the deep web <a href="https://kingdom-darkmarketplace.com/ ">Kingdom Market url </a> https://kingdom-darkmarketplace.com/ - darknet wiki link
名前
Timothylen
best card shops <a href="https://kingdomdarkmarket.com/ ">versus project darknet market </a> https://kingdomdarkmarket.com/ - darknet markets reddit
名前
Davidinton
best australian darknet market <a href="https://kingdommarketplacee.com/ ">dark market onion </a> https://kingdommarketplacee.com/ - reliable darknet markets lsd
名前
Baaket
blockchain darknet markets <a href="https://kingdom-online-drugs.com/ ">dark markets lithuania </a> https://kingdomonionmarket.com/ - darknet onion markets
名前
BillyNut
dark markets monaco <a href="https://darkweb-kingdom.com/ ">search darknet markets </a> https://darkweb-kingdom.com/ - how to access dark net
名前
BrettUttep
onion market url <a href="https://kingdom-darkweb-drugstore.com/ ">dark markets india </a> https://kingdom-darkweb-drugstore.com/ - darknet drugs australia
名前
Baaket
deep web links 2023 reddit <a href="https://kingdom-dark-market.com/ ">dark markets brazil </a> - what darknet markets are available
名前
Ronaldtic
darknet bank accounts <a href="https://heinekenmarketplace24.com/ ">Heineken Express darknet </a> https://heineken-marketplace.com/ - deep web links 2023 reddit
名前
CharlieZoose
darkweb форум <a href="https://kingdomoniondarkmarket.com/ ">best darknet market for lsd </a> https://kingdomoniondarkweb.com/ - onion links 2023
名前
WesleyPex
dark web market <a href="https://kingdomdrugsmarket.com/ ">dark markets malaysia </a> https://kingdomdrugsmarket.com/ - darknet dream market
名前
ScottAduch
crypto market darknet <a href="https://heinekenurl.com/ ">best darknet market for weed uk </a> https://heinekenmarketurl.com/ - deep web drug links
名前
AndrewTelve
dark web sites xxx <a href="https://darkfoxonionmarket.com/ ">dot onion websites </a> https://darkfoxonlinedrugs.com/ - dark web directory
名前
Davidven

コメントを追加

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