【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 finland <a href="https://kingdomdarkmarketplace.com/ ">tor2door link </a> https://kingdomdarkmarketplace.com/ - adresse onion black market
名前
Ralphzet
darknet market pills vendor <a href="https://heinekenmarketlink.com/ ">blackweb darknet market </a> https://heinekenmarketlink.com/ - darknet market noobs bible
名前
BrandonWaype
Abacus link <a href="https://kingdommarketurl.com/ ">best darknet market 2023 reddit </a> https://kingdommarketurl.com/ - reddit darknet market uk
名前
Hellyzes
how to get on darknet market <a href="https://kingdommarket-links.com/ ">black market websites 2023 </a> https://kingdommarket-darknet.com/ - deep web cc sites
名前
CorryViarD
australian darknet vendors <a href="https://kingdomdarkmarketonline.com/ ">deep web drugs </a> https://kingdom-darkmarket-online.com/ - tramadol dark web
名前
CharlesNuh
dark markets brazil <a href="https://heinekendarknetdrugstore.com/ ">darknet black market list </a> https://heinekendarknetdrugstore.com/ - darkmarket
名前
RichardDek
dark markets germany <a href="https://kingdom-darknet-drugstore.com/ ">darknet market noobs </a> https://kingdom-darknet-drugstore.com/ - Abacus Market darknet
名前
Julianacecy
Abacus darknet Market <a href="https://heineken-darknet.com/ ">dark markets croatia </a> https://heineken-darknet.com/ - deep web deb
名前
Michaeltus
dark web search engine 2023 <a href="https://kingdom-drugs-market.com/ ">dark markets luxembourg </a> https://kingdom-drugs-market.com/ - top 10 dark web url
名前
WilliamNaw
dark web drugs nz <a href="https://heinekenurl.com/ ">dark markets peru </a> https://heinekenurl.com/ - list of dark net markets
名前
Charlescob
<a href="https://v.gd/pGjYuN ">529041944</a>
名前
qiphcnyj
darknet market search engine <a href="https://heinekenonlinedrugs.com/ ">onion marketplace drugs </a> https://heinekenonlinedrugs.com/ - brucelean darknet market
名前
Stevejails
cypher market darknet <a href="https://darkfox-onion-darkmarket.com/ ">darknet market noobs guide </a> https://darkfoxdarkwebdrugstore.com/ - current darknet market
名前
Jancal
darknet markets florida <a href="https://heinekenoniondarkmarket.com/ ">how to get on the dark web </a> https://heinekenoniondarkmarket.com/ - darknet markets onion address
名前
RobertKix
darknet market controlled delivery <a href="https://heinekenmarket-link.com/ ">reddit darknet markets 2023 </a> https://heinekenmarket-link.com/ - dark markets albania
名前
Robertfup
versus darknet market <a href="https://kingdommarketdarknet.com/ ">tor markets </a> https://kingdommarketdarknet.com/ - dark web escrow service
名前
Tornaddib
drug website dark web <a href="https://kingdomdarknet.com/ ">onion marketplace drugs </a> https://kingdomdarkweb.com/ - darknet credit card market
名前
JamesHub
archetyp link <a href="https://darkmarket-heineken.com/ ">tor2door link </a> https://dark-web-heineken.com/ - Heineken Express darknet
名前
HaroldHot
darknet market 2023 reddit <a href="https://heineken-onion.com/ ">darknet marketplace drugs </a> https://heineken-onion.com/ - dark markets bulgaria
名前
Dannyquord
buying on dark web <a href="https://darkmarket-kingdom.com/ ">dark markets croatia </a> https://darkmarket-kingdom.com/ - reddit working darknet markets
名前
Danielred
hacking tools darknet markets <a href="https://heineken-online-drugs.com/ ">best mdma vendor darknet market reddit </a> https://heinekenonionmarket.com/ - dark markets guyana
名前
Edgarlow
darknet bitcoin market <a href="https://heineken-onlinedrugs.com/ ">best darknet market for heroin </a> https://heineken-onlinedrugs.com/ - redit safe darknet markets
名前
Michaelloush
how to order from dark web <a href="https://heinekennexpress.com/ ">onion tube porn </a> https://drheinekenexpress.com/ - Kingdom darknet Market
名前
Richardvak
dark markets luxembourg <a href="https://heineken-drugs-market.com/ ">darknet cannabis markets </a> https://heineken-drugsonline.com/ - dnm xanax
名前
Brandendet
drugs dark web price <a href="https://kingdomdarkmarket.com/ ">darknet markets availability </a> https://kingdomdarkmarket.com/ - dark web store
名前
Hanstulge
outlaw market darknet <a href="https://darkfoxonlinedrugs.com/ ">mdm love drug </a> https://darkfoxonionmarket.com/ - hire an assassin dark web
名前
Davidinodo
tor darknet markets <a href="https://darkmarketkingdom.com/ ">onion deep web search </a> https://kingdomonion.com/ - vice city darknet market
名前
FrankHuluh
asap market url <a href="https://kingdomdarknetmarket.com/ ">darkweb sites reddit </a> https://kingdomdarknetmarket.com/ - asap url
名前
Crisscunc
darknet marketplace drugs <a href="https://heinekenmarketdarknet.com/ ">best fraud market darknet </a> https://heinekenmarketdarknet.com/ - how to buy bitcoin and use on dark web
名前
Josephanarm
black market cryptocurrency <a href="https://kingdommarket-url.com/ ">best darknet market 2023 </a> - cypher market
名前
ADElugh
darknet market noobs step by step <a href="https://heinekenonion.com/ ">darknet live markets </a> https://heinekenonion.com/ - how to access darknet markets reddit
名前
ZacharyBop
reddit darknet markets uk <a href="https://heineken-express-onion.com/ ">versus darknet market </a> https://heineken-express-onion.com/ - how to anonymously use darknet markets
名前
BrianFew
list of dark net markets <a href="https://kingdomdarkwebmarket.com/ ">deep web directory onion </a> https://kingdom-darkmarket.com/ - dark market onion
名前
Wendellpog
dark markets san marino <a href="https://darkweb-kingdom.com/ ">best websites dark web </a> https://dark-market-kingdom.com/ - darkweb форум
名前
Teddred
reddit where to buy drugs <a href="https://kingdom-marketplace.com/ ">nike jordan pill </a> https://darkfox-onion-darkweb.com/ - darknet drug prices
名前
WilliamRip
dark web search engine 2023 <a href="https://kingdom-onlinedrugs.com/ ">alphabay market url </a> https://kingdom-drugs-online.com/ - current list of darknet markets
名前
Shanewat
underground dumps shop <a href="https://heinekenmarketonlinee.com/ ">darknet serious market </a> https://heinekenmarketonlinee.com/ - dark web markets 2023 australia
名前
Patrickhuple
dnm xanax <a href="https://heinekendrugsmarketplace.com/ ">black market website review </a> https://heinekendrugsmarketplace.com/ - tor darknet
名前
MichaelRaf
dark web fake money <a href="https://heineken-marketplace.com/ ">asap market </a> https://heinekenmarketplace24.com/ - darknet drug dealer
名前
Georgelouse
dark web links adult <a href="https://heineken-darknet-drugstore.com/ ">darknet market list reddit </a> https://heinekendarkwebdrugstore.com/ - Kingdom Market
名前
HectorDer
how to buy drugs on darknet <a href="https://kingdom-darkmarketplace.com/ ">reddit where to buy drugs </a> https://kingdom-darkmarketplace.com/ - steroid market darknet
名前
JamesStaiz
hidden financial services deep web <a href="https://dark-market-heineken.com/ ">darkmarket list </a> https://dark-market-heineken.com/ - Abacus Market url
名前
Matthewgek
dark market onion <a href="https://kingdommarketonlinee.com/ ">darknet market alaska </a> https://drkingdommarket.com/ - darknet market xanax
名前
SmittMef
onion live links <a href="https://heinekendarkmarketonline.com/ ">dark web address list </a> https://heinekendarkmarketonline.com/ - bohemia market url
名前
Randykew
legit darknet sites <a href="https://kingdom-darknet.com/ ">escrow market darknet </a> https://kingdom-darknet.com/ - onion websites for credit cards
名前
Granttromo
black market drugs guns <a href="https://heineken-darkmarket.com/ ">dark market link </a> https://heineken-darkmarket.com/ - asap darknet market
名前
DonaldDic
dark markets 2023 <a href="https://kingdom-onion-darkweb.com/ ">top ten deep web </a> https://kingdom-onion-darkweb.com/ - deep net websites
名前
Geraldhopay
tfmpp pills <a href="https://kingdomdrugsonline.com/ ">tor dark web </a> https://kingdomonlinedrugs.com/ - dark web markets 2023
名前
Davidjoisp
Heineken Express Market <a href="https://kingdomoniondarkmarket.com/ ">darknet markets lsd-25 2023 </a> https://kingdomoniondarkmarket.com/ - dynabolts pills
名前
CraigAgeni
dark web onion markets <a href="https://darkfox-onlinedrugs.com/ ">wired darknet markets </a> https://darkfox-onlinedrugs.com/ - darknet illegal market
名前
Baaket

コメントを追加

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