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

カテゴリー

コメント

dumps shop <a href="https://kingdomurl.com/ ">dark web in spanish </a> https://kingdomurl.com/ - underground hackers black market
名前
Hellyzes
black market website names <a href="https://heineken-darknet.com/ ">underground card shop </a> https://heineken-darknet.com/ - darknet union
名前
Michaeltus
links deep web tor <a href="https://kingdom-drugsonline.com/ ">darkweb форум </a> https://kingdom-drugsonline.com/ - how to get on the dark web
名前
WilliamNaw
alphabay market <a href="https://heinekendrugsonline.com/ ">reddit darknet market australia </a> https://heinekenonlinedrugs.com/ - darknet market links
名前
Stevejails
guide to using darknet markets <a href="https://heinekenurl.com/ ">buy real money </a> https://heinekenmarketurl.com/ - wired darknet markets
名前
Charlescob
darknet markets still open <a href="https://dark-web-kingdom.com/ ">incognito market url </a> https://dark-web-kingdom.com/ - guide to darknet markets
名前
Danielred
Abacus darknet Market <a href="https://darkfox-onion-darkmarket.com/ ">marijuana dark web </a> https://darkfox-onion-darkmarket.com/ - darknet markets 2023 updated
名前
Jancal
how to access darknet market <a href="https://heinekenoniondarkmarket.com/ ">dark web drugs australia </a> https://heinekenoniondarkweb.com/ - open darknet markets
名前
RobertKix
xanax darknet reddit <a href="https://heinekenmarket-link.com/ ">darknet drugs guide </a> https://heinekenmarket-links.com/ - tor websites reddit
名前
Robertfup
darknet markets list reddit <a href="https://kingdom-markett.com/ ">how to enter the black market online </a> https://kingdom-markett.com/ - dark markets slovenia
名前
Tornaddib
list of darknet markets reddit <a href="https://darkfoxonlinedrugs.com/ ">darknet market comparison </a> https://darkfoxonionmarket.com/ - how to access dark web markets
名前
Davidinodo
dark markets south korea <a href="https://kingdomdarkweb.com/ ">dark markets thailand </a> https://kingdomdarknet.com/ - darknet markets best
名前
JamesHub
new onion darknet market <a href="https://dark-web-heineken.com/ ">darknet markets may 2023 </a> https://darkmarket-heineken.com/ - Kingdom Market darknet
名前
HaroldHot
darknet market link updates <a href="https://heineken-onion.com/ ">Kingdom url </a> https://heineken-onion.com/ - darknet market oxycontin
名前
Dannyquord
darknet black market sites <a href="https://heinekennexpress.com/ ">bitcoin black market </a> https://heinekennexpress.com/ - adress darknet
名前
Richardvak
dark web in spanish <a href="https://heineken-drugsonline.com/ ">darknet market sites and how </a> https://heineken-drugsonline.com/ - the dark web url
名前
Brandendet
darknet market noobs reddit <a href="https://kingdommarket-online.com/ ">darknet markets noob </a> https://kingdommarket-online.com/ - reddit darknet market 2023
名前
Hanstulge
darknet market list url <a href="https://dark-market-kingdom.com/ ">how to buy from darknet </a> https://dark-market-kingdom.com/ - dark web link
名前
Teddred
darknet seiten dream market <a href="https://heinekenonionmarket.com/ ">best dark web marketplaces 2023 </a> https://heineken-online-drugs.com/ - buying drugs on darknet reddit
名前
Edgarlow
florida darknet markets <a href="https://heineken-drugs-online.com/ ">darknet drugs sites </a> https://heineken-drugs-online.com/ - black market net
名前
Michaelloush
drugs on the dark web <a href="https://darkmarketkingdom.com/ ">darknet litecoin </a> https://darkmarketkingdom.com/ - darknet market list 2023
名前
FrankHuluh
list of dark net markets <a href="https://kingdomdarknetmarket.com/ ">dark market </a> https://darkfoxdarknetdrugstore.com/ - crypto market darknet
名前
Crisscunc
what is darknet markets <a href="https://heinekenmarketdarknet.com/ ">deep web trading </a> https://heinekenmarketdarknet.com/ - cypher market link
名前
Josephanarm
underground hackers black market <a href="https://kingdommarket-url.com/ ">most reliable darknet markets </a> - alphabay link
名前
ADElugh
deep web links updated <a href="https://darkwebheineken.com/ ">darknet markets still open </a> https://heineken-express-onion.com/ - asap market
名前
BrianFew
darknet markets working links <a href="https://kingdomdarkwebmarket.com/ ">archetyp market link </a> https://kingdom-darkmarket.com/ - dark markets russia
名前
Wendellpog
florida darknet markets <a href="https://heinekenonion.com/ ">darknet market search engine </a> https://darkmarketheineken.com/ - black market website
名前
ZacharyBop
darknet drug market <a href="https://kingdom-marketplace.com/ ">dark web vendors </a> https://darkfox-onion-darkweb.com/ - xanax darknet markets reddit
名前
WilliamRip
how to dark web reddit <a href="https://kingdom-drugs-online.com/ ">list of darknet drug markets </a> https://kingdom-drugs-online.com/ - darknet market status
名前
Shanewat
dark markets greece <a href="https://heinekenn-express.com/ ">drugs on the deep web </a> https://heinekenn-express.com/ - darkweb sites reddit
名前
Patrickhuple
credit card dumps dark web <a href="https://heinekendrugsmarket.com/ ">incognito market darknet </a> https://heinekendrugsmarketplace.com/ - the dark market
名前
MichaelRaf
best card shops <a href="https://heineken-marketplace.com/ ">darkmarkets </a> https://heinekenmarketplace24.com/ - darknet seiten liste
名前
Georgelouse
darknet markets norge <a href="https://heineken-darknet-drugstore.com/ ">market deep web 2023 </a> https://heinekendarkwebdrugstore.com/ - darknet market lightning network
名前
HectorDer
dynabolts pills <a href="https://kingdom-onion-darkweb.com/ ">site darknet onion </a> https://kingdom-onion-darkweb.com/ - current darknet markets
名前
Geraldhopay
dark net market list reddit <a href="https://darkfox-onlinedrugs.com/ ">best websites dark web </a> https://darkfox-onlinedrugs.com/ - Abacus link
名前
Baaket
dark markets portugal <a href="https://kingdom-darkmarketplace.com/ ">dark market reddit </a> https://kingdom-darkmarketplace.com/ - darknet markets working links
名前
JamesStaiz
bohemia url <a href="https://kingdom-onion.com/ ">darknet website for drugs </a> https://darkwebkingdom.com/ - deep dark web
名前
Danired
darknet onion links drugs <a href="https://heinekendarkmarketonline.com/ ">what darknet markets are open </a> https://heinekendarkmarketonline.com/ - darknet market busts
名前
Randykew
darknet markets fake id <a href="https://dark-market-heineken.com/ ">2023 darknet markets </a> https://darkweb-heineken.com/ - dark web engine search
名前
Matthewgek
darknet sites url <a href="https://drkingdommarket.com/ ">dark web links 2023 </a> https://kingdommarketonlinee.com/ - the darknet markets
名前
SmittMef
darkfox darknet market <a href="https://kingdomonlinedrugs.com/ ">dark web drugs </a> https://kingdomdrugsonline.com/ - darknet markets noob
名前
Davidjoisp
dark web sites links <a href="https://heineken-darkmarket.com/ ">darknet market bust </a> https://heinekendarkwebmarket.com/ - dark markets liechtenstein
名前
DonaldDic
nike jordan pill <a href="https://kingdom-darkweb.com/ ">dark markets netherlands </a> https://kingdom-darknet.com/ - darknet markets norway 2023
名前
Granttromo
popular dark websites <a href="https://kingdomoniondarkmarket.com/ ">Abacus Market </a> https://kingdomoniondarkmarket.com/ - darknet serious market
名前
CraigAgeni
darknet wiki link <a href="https://kingdom-onion-market.com/ ">dark web markets reddit </a> https://kingdom-onion-market.com/ - dark web markets 2023
名前
DamonLat
dynabolts pills <a href="https://kingdom-darkweb-drugstore.com/ ">onion deep web search </a> https://heinekenmarketplacee.com/ - vice city market url
名前
Randytiz
darknet drug vendor that takes paypal <a href="https://heineken-markett.com/ ">deep web onion url </a> https://heineken-markett.com/ - archetyp market url
名前
JamesseM
underground market place darknet <a href="https://heineken-onion-market.com/ ">ordering drugs on dark web </a> https://heineken-onion-market.com/ - darknet drug store
名前
JackieDuart
dot onion websites <a href="https://heineken-darkwebmarket.com/ ">search darknet markets </a> https://heineken-darkwebmarket.com/ - dark web step by step
名前
JasonGribe
darknet escrow markets <a href="https://kingdomdrugsmarketplace.com/ ">darknet markets for steroids </a> https://kingdomdrugsmarketplace.com/ - Heineken Express url
名前
Sirket

コメントを追加

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