【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 websites <a href="https://cyberdarkmarkets.com/ ">dark web search engines </a>
名前
HaroldHot
the dark internet <a href="https://tordarknetmarket2022.shop/ ">dark web drug marketplace </a>
名前
Randytiz
best darknet markets <a href="https://tordarknetmarkets2023.shop/ ">dark web access </a>
名前
Robertfup
deep web search <a href="https://torwebdarknet.shop/ ">tor marketplace </a>
名前
ZacharyBop
dark market onion <a href="https://darknet-marketss.com/ ">dark web sites </a>
名前
Michaelloush
deep dark web <a href="https://privatedarkwebmarkets.shop/ ">dark markets 2023 </a>
名前
Crisscunc
bitcoin dark web <a href="https://thetormarket.com/ ">darknet drugs </a>
名前
Ralphzet
dark market onion <a href="https://tordarkweblist.link/ ">darknet market lists </a>
名前
Julianacecy
deep web drug store <a href="https://tordarkwebmarketlink.link/ ">darknet markets 2023 </a>
名前
Patrickhuple
darkmarket 2023 <a href="https://darknet-market-linkss.com/ ">dark markets 2022 </a>
名前
Edgarlow
tor market url <a href="https://tordarknetmarketlist.com/ ">dark websites </a>
名前
Josephanarm
tor markets 2023 <a href="https://thedarkwebmarkest.com/ ">dark web access </a>
名前
Hellyzes
dark web market <a href="https://tordarkmarketplace.com/ ">dark net </a>
名前
Shanewat
the dark internet <a href="https://tor-market-darknet.link/ ">dark web site </a>
名前
Granttromo
blackweb official website <a href="https://tordarknetmarkets2023.com/ ">tor dark web </a>
名前
JamesseM
darknet seiten <a href="https://darknetmarketoffers.com/ ">darknet links </a>
名前
Stevejails
darknet market <a href="https://thedarkmarketpoint.link/ ">deep web sites </a>
名前
Tornaddib
deep web drug url <a href="https://thedarkwebmarket.com/ ">dark websites </a>
名前
SmittMef
darknet market lists <a href="https://tor-markets-darkweb.link/ ">tor markets 2022 </a>
名前
Davidjoisp
dark market list <a href="https://darkmarketslist.link/ ">darknet markets 2023 </a>
名前
RichardDek
drug markets onion <a href="https://darknetmarketsapp.com/ ">deep web drug links </a>
名前
BrianFew
dark web market <a href="https://tordarkwebmarkets2022.link/ ">dark market 2023 </a>
名前
JuliusEsobe
onion market <a href="https://privatedarknetmarkets.shop/ ">darknet seiten </a>
名前
Davidinodo
bitcoin dark web <a href="https://heineken-express.link/ ">darkmarket url </a>
名前
RobertKix
deep web drug url <a href="https://tormarketwebxx.com/ ">darknet drugs </a>
名前
DonaldDic
deep dark web <a href="https://thetormarket.shop/ ">deep web drug store </a>
名前
JamesStaiz
dark web links <a href="https://tordarknetmarket24.shop/ ">blackweb </a>
名前
Georgelouse
dark web sites links <a href="https://privatedarkwebmarket.com/ ">blackweb official website </a>
名前
WilliamRip
deep web drug url <a href="https://globaldarknetmarket.com/ ">darknet search engine </a>
名前
Brandendet
dark web drug marketplace <a href="https://tor-marketplace24.link/ ">dark web market list </a>
名前
Danielred
darknet links <a href="https://tor-marketplace24.shop/ ">dark market onion </a>
名前
Teddred
darknet seiten <a href="https://thedarkwebmarket.link/ ">darknet site </a>
名前
Hanstulge
darkmarket 2023 <a href="https://tordarkwebmarkets2022.com/ ">darkweb marketplace </a>
名前
TimmyMeexy
dark web sites links <a href="https://tordarkmarketurl.shop/ ">tor markets </a>
名前
CraigAgeni
deep dark web <a href="https://tordarkweblist.shop/ ">dark internet </a>
名前
BrandonWaype
darknet links <a href="https://tormarketwebxx.shop/ ">tor markets </a>
名前
JasonGribe
darkmarket <a href="https://tor-markets-darknet.shop/ ">deep web drug markets </a>
名前
Sirket
tor markets 2023 <a href="https://torwebdarknet.com/ ">dark websites </a>
名前
Randykew
tor market links <a href="https://darkmarketlist.link/ ">dark internet </a>
名前
JackieDuart
dark web market links <a href="https://privatedarkwebmarket.shop/ ">dark web site </a>
名前
Jancal
tor market url <a href="https://tordarknetmarket2022.com/ ">dark net </a>
名前
Geraldhopay
blackweb <a href="https://privatedarkmarkets.shop/ ">tor market url </a>
名前
Baaket
darknet seiten <a href="https://tordarkwebmarket.shop/ ">dark market 2023 </a>
名前
Richardvak
dark markets 2023 <a href="https://bestmarketdarknet.com/ ">darknet seiten </a>
名前
MichaelRaf
[img]https://media.cnn.com/api/v1/images/stellar/prod/230118192538-stryker-combat-vehicles-file.jpg?c=16x9&q=w_800,c_fill[/img] US will send Stryker combat vehicles to Ukraine for first time as part of $2.5 billion security packageCNNUkraine's Swedish-Made CV90 Fighting Vehicles Are Meant To Hunt Enemy Armor In The WoodsForbesU.S. officials advise Ukraine to wait on offensive, official saysReuters plsHelpUkraine01202320
https://661isclinitdasb126.blogspot.com/2022/12/elocon-01-soluzione-cutanea-30-g.html https://276tinamosup412f.blogspot.com/2023/01/does-sleep-quality-change-after-switch.html https://84riesodachitj12aog.blogspot.com/2022/12/i-5-migliori-diuretici-naturali-per.html https://7frinevtarozf12iy7.blogspot.com/2022/12/gonfia-come-un-pallone-e-leffetto.html https://7apacarmadg12tudt.blogspot.com/2023/01/furosemide-cose-come-e-quando-si-assume.html https://7geodapege9r12hi.blogspot.com/2022/12/my-experience-with-accutane.html https://898placbusmonqy125.blogspot.com/2022/12/buy-elocon-ointment-online.html https://itculcaehimj128.blogspot.com/2022/12/online-dental-products-suppliers-uk.html https://6litomageyo12c.blogspot.com/2023/01/elocon-ointment-patient-information.html https://232sterliapuzacz12r46.blogspot.com/2022/12/alanyada-uyusturucu-operasyonuna-16.html https://21rioloreyubh128v1g.blogspot.com/2022/12/table-9-combination-ics-laba-inhalers.html https://8hunlenishi4m12jhn.blogspot.com/2023/01/ventolin-cfc-free-inhaler-uses-dosage.html https://69coaplagdaedzu0f12aj.blogspot.com/2022/12/a-message-to-asthma-sufferers-about.html https://0compneruete7y12tfb.blogspot.com/2022/12/inderal-30cpr-40mg.html https://79afmiliabu5f12ho3d.blogspot.com/2023/01/versamento-pleurico-cause-sintomi-cura.html https://80nestreserboe81219r.blogspot.com/2022/12/elocon-0-1-cream-10-uses-side-effects.html https://22lajecvihak812kndw.blogspot.com/2022/12/sertralina-zoloft-tatig-interazioni.html https://709ticoverchi6w12xtz.blogspot.com/2022/12/treatment-of-seborrheic-dermatitis.html https://4lofaterdzurk127.blogspot.com/2023/01/symbicort-budesonide-formoterol.html https://5plicibinivi12dj3.blogspot.com/2022/12/furosemide-40-100-mg-lasix-compresse.html https://849flecuranbo8r121.blogspot.com/2023/01/furosemide-per-uso-orale.html https://raconmulmawy125ff7.blogspot.com/2022/12/buy-elocon-scalp-lotion-online.html https://fremdirogak3121.blogspot.com/2022/12/la-differenza-tra-pomata-crema-e.html https://94apfanmishirf12k1.blogspot.com/2022/12/lasix-inf-5f-250mg-25ml.html https://crasmiscoedora12hbnc.blogspot.com/2022/12/farmacia-online-con-oltre-50000-prodotti.html https://989crepmaraso1812txo7.blogspot.com/2023/01/symbicort-and-price-generic-brand-name.html https://1ulvitiayoli12c.blogspot.com/2023/01/sectral-400-mg-compresse-rivestite-con.html https://612lybvastiowazm12pn.blogspot.com/2022/12/buy-elocon-cream-ointment-online.html https://194erosrawan812at.blogspot.com/2022/12/ventolin-albuterol-inhaler-online-us.html https://byerly2315.nbeautysalon.nl https://chesnutt61528.internetofallthings.nl https://fusca71169.moodmind.pl https://gilden25480.djkai.nl https://wence67234.nbeautysalon.nl https://adjutant87528.fauto.es https://margaris22335.djkai.nl https://valle83746.fauto.es https://buglisi76993.moodmind.pl https://rettele36433.arnevanommen.nl https://collazo16520.moodmind.pl https://bracetty73741.mateodiaz.es https://bernasconi67998.wftv.live https://labuda18251.ekopartners.nl https://navo51092.bbq-direct.nl https://moch82089.tipsvoortech.nl https://caughorn37429.lars-ortho.nl https://mesrobian15584.planmyday.pl https://colaizzo23778.rrbricks.nl https://nosel21748.planmyday.pl https://roegner69120.lars-ortho.nl https://krider37130.rrbricks.nl https://stpeters12684.bbq-direct.nl https://deramus16300.mateodiaz.es https://kosuta14660.arnevanommen.nl https://balich54666.tipsvoortech.nl https://lasota52306.planmyday.pl
名前
Louisdor
dark market 2023 <a href="https://torwebmarketplace.link/ ">darkmarket list </a>
名前
Dannyquord
darkmarkets <a href="https://tor-darkmarkets-online.shop/ ">dark market link </a>
名前
JamesHub
tor darknet <a href="https://thedarknetmarket.com/ ">darknet marketplace </a>
名前
CorryViarD
darknet site <a href="https://tor-market-darkweb.shop/ ">darknet marketplace </a>
名前
Danired
dark web access <a href="https://tor-darkmarkets-online.com/ ">dark web search engines </a>
名前
FrankHuluh

コメントを追加

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