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

カテゴリー

コメント

darknet sites <a href="https://asap-onion.link/ ">dark markets </a>
名前
JackieDuart
drug markets onion <a href="https://tordarkweblist.com/ ">darknet markets 2023 </a>
名前
BrandonWaype
deep web search <a href="https://torwebmarketplace.com/ ">darkmarket </a>
名前
ZacharyBop
dark web market list <a href="https://tordarkwebmarketlinks.shop/ ">darknet market </a>
名前
TimmyMeexy
the dark internet <a href="https://tormarketwebxx.shop/ ">darknet markets 2023 </a>
名前
JasonGribe
dark internet <a href="https://thedarkmarketpoint.shop/ ">darknet markets 2023 </a>
名前
CorryViarD
blackweb official website <a href="https://worldwidedarknetmarket.com/ ">deep web drug links </a>
名前
MichaelRaf
deep web drug links <a href="https://tordarkweblist.link/ ">dark website </a>
名前
Julianacecy
how to get on dark web <a href="https://privatedarkwebmarkets.com/ ">dark web search engines </a>
名前
Jancal
dark web search engines <a href="https://tor-markets2023.link/ ">dark markets </a>
名前
WilliamNaw
dark web sites links <a href="https://tordarkmarketplace.shop/ ">dark web websites </a>
名前
Ronaldevica
dark web market list <a href="https://tor-darkmarkets-online.link/ ">dark markets 2023 </a>
名前
JamesHub
[img]https://www.europarl.europa.eu/resources/library/images/20230117PHT67301/20230117PHT67301_original.jpg[/img] Ukraine war: MEPs push for special tribunal to punish Russian ...European Parliament plsHelpUkraine01202319
https://4haucasforgokm12iz0b.blogspot.com/2022/12/normal-recete-ile-verilmesi-gereken.html https://10prinarvirgat8123bt.blogspot.com/2023/01/papa-ha-assunto-il-diuretico-lasix-per.html https://puncvencuson612ps.blogspot.com/2023/01/la-dieta-chetogenica-la-chetosi-ed-i.html https://4lofaterdzurk127.blogspot.com/2023/01/eloconcrema-30g-01-farmacia-murtas.html https://92clivitcunkuro12s7j.blogspot.com/2023/01/bentelan-cosa-serve-principio-attivo-e.html https://vimicuszet212os.blogspot.com/2022/12/lasix-effetti-indesiderati-del.html https://3tinvehautony129pb.blogspot.com/2023/01/alternative-to-symbicort-hello-ive.html https://4concronawo1a12ks.blogspot.com/2022/12/buy-elocon-cream-elocon-ointment-0-1.html https://7ciacacbipeyz12xor0.blogspot.com/2023/01/treatment-of-utis-due-to-klebsiella.html https://chondlenuwagh12oujl.blogspot.com/2022/12/prelone-bula-original-obtida.html https://newsfrom308temppijugu42jje8.blogspot.com/2023/01/comprare-viagra-in-bari-non-ci-sono.html https://laumennibeg812wl.blogspot.com/2023/01/le-cause-del-prurito-anale.html https://54geserlemuu612r.blogspot.com/2022/12/everything-you-need-to-know-before.html https://804llarabgedaqs121.blogspot.com/2022/12/fio-o-foro-leggi-argomento-la-canapa-o.html https://31haetermezu6d12myp.blogspot.com/2022/12/fimosi-bambini-o-aderenze-balano.html https://specalagpog5129d9r.blogspot.com/2023/01/farmaci-betabloccanti-cosa-sono-e-come.html https://sortaceska2912r.blogspot.com/2023/01/elocom-crema-30g-01.html https://2silricaugene12sg.blogspot.com/2022/12/albuterol-hfa-and-proventil-ventolin.html https://62calmatiowajr12n.blogspot.com/2022/12/farmacia-online-con-oltre-50000-prodotti.html https://58opodviia312d0.blogspot.com/2023/01/buy-albuterol-sulfate-online-ventolin.html https://9tercverperwa9z12s.blogspot.com/2023/01/elocon-cream-patient-information.html https://335mentuveji6s12y0ys.blogspot.com/2022/12/elocon-crema-unguento-foglio.html https://laumennibeg812wl.blogspot.com/2023/01/antidepresan-ve-cinsellik-kadn-sitesi.html https://4sumpsaulutrovj12v7j8.blogspot.com/2022/12/inderal-40-mg-30-compresse.html https://77stigagconnu54129j8.blogspot.com/2022/12/emicrania-profilassi-farmacologica.html https://141fimoltorjilv12m3.blogspot.com/2022/12/bambino-5-mesi-con-dermatite-atopica.html https://subcnienakuig120nqt.blogspot.com/2023/01/usi-della-crema-elocon-cosa-serve-e.html https://043foeratianujx12e.blogspot.com/2023/01/le-domande-su-dermatite-da-pannolino.html https://11fracnirithpupu12y.blogspot.com/2022/12/aicmt-farmaci-da-usare-con-cautela.html https://beamer14558.internetofallthings.nl https://zahourek7270.eq-consulting.nl https://hafen43106.immobilienkatalog.pl https://markum57409.fauto.es https://nothnagel28296.fauto.es https://tukes70225.directslotenmakers.nl https://economus23700.wftv.live https://migliori69350.internetofallthings.nl https://condry20216.fauto.es https://whitcraft42409.internetofallthings.nl https://dagostino22849.lars-ortho.nl https://zahradnik44591.eq-consulting.nl https://lubic83499.impresoydigital.es https://wahs82458.immobilienkatalog.pl https://brislan35789.arosbv.nl https://gruhn55843.tipsvoortech.nl https://zarn7398.fauto.es https://soltau53864.internetofallthings.nl https://gianunzio24951.ekopartners.nl https://wacyk72705.planmyday.pl https://rothchild59273.ekopartners.nl
名前
Louisdor
drug markets dark web <a href="https://thedarknetmarket.link/ ">dark market url </a>
名前
ADElugh
deep dark web <a href="https://tordarkwebmarket.com/ ">dark market link </a>
名前
Charlescob
deep web search <a href="https://tordarkwebslist.link/ ">darknet site </a>
名前
Michaeltus
the dark internet <a href="https://cyberdarkmarkets.com/ ">deep web sites </a>
名前
HaroldHot
deep web search <a href="https://tordarknetmarkets2023.shop/ ">dark web link </a>
名前
Robertfup
free dark web <a href="https://tor-market-darkweb.com/ ">dark web market links </a>
名前
Wendellpog
deep web drug markets <a href="https://darkmarketbridge.com/ ">dark web markets </a>
名前
Michaelloush
tor markets links <a href="https://tordarknetmarket2022.shop/ ">deep web drug url </a>
名前
Randytiz
darknet links <a href="https://thedarkwebmarkest.com/ ">tor dark web </a>
名前
Hellyzes
darknet websites <a href="https://thetormarket.com/ ">darknet site </a>
名前
Ralphzet
deep web search <a href="https://tordarkmarketplace.link/ ">deep web drug markets </a>
名前
Shanewat
dark market link <a href="https://darknet-market-linkss.com/ ">tor markets 2023 </a>
名前
Edgarlow
darknet drug market <a href="https://privatedarknetmarkets.com/ ">darkmarket 2022 </a>
名前
Baaket
dark web market <a href="https://tordarkwebmarketlink.link/ ">dark web drug marketplace </a>
名前
Patrickhuple
dark web search engines <a href="https://privatedarkwebmarket.link/ ">tor markets links </a>
名前
WilliamRip
darknet drug store <a href="https://tordarkwebmarketlinks.com/ ">darknet sites </a>
名前
DavidDes
darknet market <a href="https://privatedarkwebmarkets.link/ ">dark market 2023 </a>
名前
Crisscunc
tor market links <a href="https://tor-markets-darknet.com/ ">deep web drug markets </a>
名前
FrankHuluh
dark markets <a href="https://tor-darkmarket-online.shop/ ">free dark web </a>
名前
CharlesNuh
dark web links <a href="https://tordarknetmarketlist.com/ ">darkmarkets </a>
名前
Josephanarm
dark web market <a href="https://tor-market-darknet.link/ ">dark market </a>
名前
Granttromo
tor marketplace <a href="https://tordarknetmarketlist.shop/ ">dark web links </a>
名前
JamesseM
dark web market links <a href="https://tor-markets-darkweb.shop/ ">tor market </a>
名前
Davidjoisp
dark web drug marketplace <a href="https://torwebdarknet.com/ ">tor market url </a>
名前
Randykew
darknet websites <a href="https://darknetmarketoffers.com/ ">darknet drug market </a>
名前
Stevejails
dark web websites <a href="https://thedarkwebmarket.com/ ">darknet search engine </a>
名前
SmittMef
darknet drugs <a href="https://worldmarkets.link/ ">drug markets dark web </a>
名前
RobertKix
black internet <a href="https://darkmarketslist.link/ ">darknet drugs </a>
名前
RichardDek
tor market <a href="https://thedarkmarketpoint.com/ ">the dark internet </a>
名前
Tornaddib
darknet markets 2023 <a href="https://tordarknetmarket2022.com/ ">deep web markets </a>
名前
Geraldhopay
darknet marketplace <a href="https://bestdarkmarketlist.com/ ">dark web sites links </a>
名前
BrianFew
dark market 2022 <a href="https://tordarkwebmarkets2022.shop/ ">darknet drug store </a>
名前
JuliusEsobe
dark market link <a href="https://privatedarknetmarkets.link/ ">deep web drug links </a>
名前
Davidinodo
deep web markets <a href="https://darknetmarketsonline.link/ ">tor markets links </a>
名前
HectorDer
deep web links <a href="https://tormarketwebxx.com/ ">dark web markets </a>
名前
DonaldDic
deep dark web <a href="https://torwebmarketplace.link/ ">dark market onion </a>
名前
Dannyquord
deep web drug store <a href="https://marketdarkweb.com/ ">dark markets </a>
名前
Brandendet

コメントを追加

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