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

カテゴリー

コメント

best dark web counterfeit money <a href="https://darkfoxonlinedrugs.com/ ">market street darknet </a> https://darkfoxonlinedrugs.com/ - darknet market steroids
名前
Davidinodo
dark markets peru <a href="https://darkweb-heineken.com/ ">darknet onion markets </a> https://darkweb-heineken.com/ - darknet market and monero
名前
Matthewgek
how to buy bitcoin for the dark web <a href="https://kingdommarketonlinee.com/ ">wikipedia darknet market </a> https://drkingdommarket.com/ - darknet market credit cards
名前
SmittMef
tor websites reddit <a href="https://heinekendarkmarketonline.com/ ">dark market url </a> https://heinekendarkmarketonline.com/ - new onion darknet market
名前
Randykew
tor darknet <a href="https://kingdom-darkwebmarket.com/ ">new alphabay darknet market </a> https://kingdom-darkmarketplace.com/ - dark web sites
名前
JamesStaiz
dark markets indonesia <a href="https://heineken-darknet-drugstore.com/ ">reddit darknet market list </a> https://heineken-darknet-drugstore.com/ - the darknet market reddit
名前
HectorDer
darknet market vendors <a href="https://darkfox-onion-darkweb.com/ ">deep web directory onion </a> https://darkfox-onion-darkweb.com/ - lsd drug wiki
名前
WilliamRip
assassination market darknet <a href="https://kingdom-darknet.com/ ">onion sex shop </a> https://kingdom-darkweb.com/ - best drug darknet
名前
Granttromo
dark markets austria <a href="https://heineken-darkmarket.com/ ">top 10 dark websites </a> https://heineken-darkmarket.com/ - dark web link
名前
DonaldDic
dark chart <a href="https://kingdomdrugsonline.com/ ">darknet drugs india </a> https://kingdomonlinedrugs.com/ - darknet market links reddit
名前
Davidjoisp
tor market links <a href="https://kingdomoniondarkweb.com/ ">decentralized darknet market </a> https://kingdomoniondarkmarket.com/ - drug markets onion
名前
CraigAgeni
adresse onion black market <a href="https://dark-market-kingdom.com/ ">dark markets philippines </a> https://darkweb-kingdom.com/ - best darknet market for counterfeit
名前
Teddred
darknet market ddos <a href="https://heinekenmarket-darknet.com/ ">darknet dream market link </a> https://heinekenmarket-darknet.com/ - alphabay market url
名前
JamesseM
duckduckgo onion site <a href="https://kingdom-darkweb-drugstore.com/ ">which darknet markets accept zcash </a> https://heinekenmarketplacee.com/ - safe list of darknet market links
名前
Randytiz
vice city darknet market <a href="https://kingdomurl.com/ ">Heineken Express darknet </a> https://kingdommarketurl.com/ - darknet seiten liste
名前
Hellyzes
dark web hitman for hire <a href="https://kingdommarket-darknet.com/ ">phenazepam pills </a> https://kingdommarket-darknet.com/ - back market trustworthy
名前
CorryViarD
best darknet market for counterfeit <a href="https://heineken-onion-market.com/ ">red ferrari pills </a> https://heineken-onion-market.com/ - onion link search engine
名前
JackieDuart
dark web store <a href="https://heineken-darkwebmarket.com/ ">best darknet market may 2023 reddit </a> https://heineken-darkwebmarket.com/ - darknet market news
名前
JasonGribe
bitcoin market on darknet tor <a href="https://kingdom-onion-darkweb.com/ ">Kingdom url </a> https://kingdomdarknetdrugstore.com/ - Abacus Market link
名前
Geraldhopay
dark web markets 2023 <a href="https://kingdomdrugsmarket.com/ ">how to buy bitcoin for the dark web </a> https://kingdomdrugsmarket.com/ - black market online website
名前
Sirket
biggest darknet market 2023 <a href="https://heinekendrugsonline.com/ ">darknet onion markets reddit </a> https://heinekenonlinedrugs.com/ - reddit darknet markets list
名前
Stevejails
french dark web <a href="https://kingdomdarkmarketplace.com/ ">where to find onion links </a> https://kingdomdarkmarketplace.com/ - darkweb marketplace
名前
Ralphzet
online black market uk <a href="https://darkfox-onlinedrugs.com/ ">best darknet markets for vendors </a> https://darkfox-onlinedrugs.com/ - what are darknet drug markets
名前
Baaket
fullz darknet market <a href="https://kingdomdarkmarketonline.com/ ">back market trustworthy </a> https://kingdom-darkmarket-online.com/ - reddit darknet market superlist
名前
CharlesNuh
dark web login guide <a href="https://darkwebkingdom.com/ ">darknet market carding </a> https://kingdom-onion.com/ - reddit darknet markets uk
名前
Danired
darknet black market sites <a href="https://heinekenmarket-url.com/ ">blacknet drugs </a> https://heinekenmarket-url.com/ - Kingdom link
名前
BrandonWaype
dark net market links 2023 <a href="https://kingdom-onion-market.com/ ">darknet market adderall </a> https://kingdom-onion-market.com/ - dark web xanax
名前
DamonLat
darknet drug prices uk <a href="https://heinekenoniondarkmarket.com/ ">pill with crown on it </a> https://heinekenoniondarkmarket.com/ - dark web search engines 2023
名前
RobertKix
deep web markets <a href="https://heineken-darkweb.com/ ">darknet market noobs </a> https://heineken-darkweb.com/ - darknet market steroids
名前
Michaeltus
darknet adress <a href="https://heineken-onion-darkweb.com/ ">best darknet market 2023 reddit </a> https://heinekendarknetdrugstore.com/ - darknet market guide
名前
RichardDek
buying from darknet market with electrum <a href="https://heinekenmarketurl.com/ ">legit darknet sites </a> https://heinekenmarketurl.com/ - dark markets iceland
名前
Charlescob
darknet union <a href="https://kingdom-drugs-market.com/ ">darknet market package </a> https://kingdom-drugsonline.com/ - darknet marketplace
名前
WilliamNaw
online onion market <a href="https://kingdomonionmarket.com/ ">darknet seiten </a> https://kingdomonionmarket.com/ - dark markets south korea
名前
Ronaldevica
best fraud market darknet <a href="https://darkfox-onion-darkmarket.com/ ">shop ccs carding </a> https://darkfoxdarkwebdrugstore.com/ - current darknet markets reddit
名前
Jancal
dark markets norway <a href="https://heineken-onlinedrugs.com/ ">darknet market url list </a> https://heineken-drugs-online.com/ - back market legit
名前
Michaelloush
best darknet market for weed <a href="https://heineken-online-drugs.com/ ">darknet best drugs </a> https://heinekenonionmarket.com/ - dark web trading
名前
Edgarlow
how to get to darknet market <a href="https://kingdom-markett.com/ ">hire an assassin dark web </a> https://kingdommarketdarknet.com/ - new darknet markets
名前
Tornaddib
deep web cc shop <a href="https://heinekenmarket-links.com/ ">incognito url </a> https://heinekenmarket-links.com/ - search darknet markets
名前
Robertfup
onion links 2023 <a href="https://darkmarket-heineken.com/ ">shop ccs carding </a> https://dark-web-heineken.com/ - best black market websites
名前
HaroldHot
Kingdom darknet Market <a href="https://kingdomdarkweb.com/ ">darknet список сайтов </a> https://kingdomdarknet.com/ - darknet market adderall
名前
JamesHub
darknet drugs reddit <a href="https://heineken-onion.com/ ">best darknet market 2023 reddit </a> https://heinekenexpressonion.com/ - dark web search engines 2023
名前
Dannyquord
how to order from dark web <a href="https://heinekennexpress.com/ ">fresh onions link </a> https://heinekennexpress.com/ - tor2door market darknet
名前
Richardvak
french deep web link <a href="https://kingdommarket-online.com/ ">darknet markets wax weed </a> https://kingdomdarkmarket.com/ - underground market place darknet
名前
Hanstulge
dark markets montenegro <a href="https://kingdomonion.com/ ">versus project market url </a> https://darkmarketkingdom.com/ - darknet links market
名前
FrankHuluh
trusted darknet markets <a href="https://kingdommarket-url.com/ ">deep web search engines 2023 </a> [url=]archetyp market link [/url]
名前
ADElugh
underground market online <a href="https://kingdom-darknet-drugstore.com/ ">blockchain darknet markets </a> https://kingdomdarkwebdrugstore.com/ - dark web hitmen
名前
Julianacecy
dark web directory <a href="https://darkfoxdarknetdrugstore.com/ ">dark web search engines 2023 </a> https://kingdomdarknetmarket.com/ - dark web drug marketplace
名前
Crisscunc
darknet drug market url <a href="https://heineken-drugs-market.com/ ">versus project market darknet </a> https://heineken-drugs-market.com/ - where to find darknet market links
名前
Brandendet
dark net market links 2023 <a href="https://heinekendarknetmarket.com/ ">dark web sites links </a> https://heinekendarknetmarket.com/ - black market bank account
名前
Josephanarm
darknet markets still up <a href="https://heinekenonion.com/ ">darknet market bible </a> https://heinekenonion.com/ - deep web links reddit 2023
名前
ZacharyBop

コメントを追加

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