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

カテゴリー

コメント

how to access the dark web reddit <a href="https://drheinekenexpress.com/ ">best dark web counterfeit money </a> https://drheinekenexpress.com/ - deep web marketplaces reddit
名前
ErnestHalry
darknet markets reddit 2023 <a href="https://heinekenn-express.com/ ">tor markets </a> https://heinekenn-express.com/ - darkfox market
名前
EdwardDride
dark web shopping <a href="https://heineken-marketplace.com/ ">onion market url </a> https://heinekenmarketplace24.com/ - reddit darknet market noobs bible
名前
CharlieZoose
best market darknet drugs <a href="https://kingdom-darkmarket.com/ ">dark markets new zealand </a> https://kingdomdarkwebmarket.com/ - onion directory 2023
名前
WilliamUttep
darknet market list links <a href="https://kingdomdrugsmarket.com/ ">working darknet markets </a> https://kingdomdrugsmarket.com/ - darknet markets may 2023
名前
ScottAduch
darknet escrow markets <a href="https://darkmarketkingdom.com/ ">dark web address list </a> https://darkmarketkingdom.com/ - pill with crown on it
名前
Allenthuck
dark web prepaid cards reddit <a href="https://kingdommarketonlinee.com/ ">dark markets croatia </a> https://kingdommarketonlinee.com/ - buds express
名前
RichardIcott
darknet drugs sales <a href="https://kingdomdrugsonline.com/ ">darkfox market link </a> https://kingdomonlinedrugs.com/ - onion links 2023
名前
Ronaldwrope
dark web cheap electronics <a href="https://heinekendarknetmarket.com/ ">best darknet market links </a> https://heinekenmarketdarknet.com/ - darknet black market list
名前
EdwardHal
uncensored hidden wiki link <a href="https://kingdom-drugsonline.com/ ">cp onion </a> https://kingdom-drugsonline.com/ - ruonion
名前
Albertobut
black market webshop <a href="https://heinekenmarket-darknet.com/ ">counterfeit money dark web reddit </a> https://heinekenmarket-darknet.com/ - dark web illegal links
名前
Williammulge
the onion directory <a href="https://kingdommarket-links.com/ ">dark web sites name list </a> https://kingdommarket-darknet.com/ - dark markets singapore
名前
JamesMop
hacking tools darknet markets <a href="https://dark-web-kingdom.com/ ">cypher darknet market </a> https://darkmarket-kingdom.com/ - market onion
名前
HenryHap
fake id onion <a href="https://heinekendarkmarket.com/ ">best lsd darknet market </a> https://heinekendarkmarket.com/ - deep web drug prices
名前
EugeneGor
how to access darknet market <a href="https://heinekenonion.com/ ">dark web escrow service </a> https://heinekenonion.com/ - how to create a darknet market
名前
Zacharywah
duckduckgo onion site <a href="https://kingdomdarkmarket.com/ ">black market cryptocurrency </a> https://kingdomdarkmarket.com/ - darknet drug market
名前
Davidinton
darknet drug market url <a href="https://heinekendarkwebmarket.com/ ">reddit onion list </a> https://heinekendarkwebmarket.com/ - active darknet market urls
名前
WillisVow
archetyp market url <a href="https://kingdom-onlinedrugs.com/ ">Cocorico url </a> https://kingdom-drugs-online.com/ - legit darknet markets 2023
名前
Jimmyrox
buds express <a href="https://heinekenmarket-link.com/ ">dark markets liechtenstein </a> https://heinekenmarket-link.com/ - buying from darknet market with electrum
名前
JohnnyBiz
deep onion links <a href="https://heineken-dark-market.com/ ">darknet market noobs step by step </a> https://heineken-dark-market.com/ - dark web xanax
名前
RandyEduts
tor market list <a href="https://heinekenexpressonion.com/ ">dark markets spain </a> https://heinekenexpressonion.com/ - darkfox market darknet
名前
DavidLeape
access darknet markets <a href="https://kingdommarketurl.com/ ">how to enter the black market online </a> https://kingdommarketurl.com/ - Abacus Market
名前
KevinClimi
darknet market busts <a href="https://kingdom-markett.com/ ">what darknet markets sell fentanyl </a> https://kingdommarketdarknet.com/ - how to find the black market online
名前
Robertduelf
darknet drugs 2023 <a href="https://kingdomdarkmarketplace.com/ ">darknet online drugs </a> - deep web deb
名前
Ronaldtic
darknet markets ranked 2023 <a href="https://heinekenurl.com/ ">buying on dark web </a> https://heinekenmarketurl.com/ - buying drugs online on openbazaar
名前
AndrewTelve
0day onion <a href="https://heineken-darkmarketplace.com/ ">Heineken Express darknet Market </a> https://heineken-darkmarketplace.com/ - how to buy from darknet markets
名前
Phillipget
how to buy drugs on the darknet <a href="https://heineken-express-onion.com/ ">2023 darknet market </a> https://darkwebheineken.com/ - top darknet markets 2023
名前
Andrewbem
brucelean darknet market <a href="https://heineken-darkweb.com/ ">Heineken Express darknet Market </a> https://heineken-darkweb.com/ - dark markets uk
名前
Arnoldinfop
business college essay prompts <a href="https://payforessayu.com/">pay someone to do your essay</a> how to write a college essay reddit
名前
aborazed
tramadol dark web <a href="https://kingdom-darkweb.com/ ">where to find darknet market links </a> https://kingdom-darkweb.com/ - darknet links 2023 drugs
名前
DevinImMek
illegal black market <a href="https://heinekenmarketonlinee.com/ ">versus project market url </a> https://heinekenmarketonlinee.com/ - Kingdom Market url
名前
EdwardDride
onion seiten <a href="https://heinekennexpress.com/ ">dark markets croatia </a> https://drheinekenexpress.com/ - darknet software market
名前
ErnestHalry
reddit darknet markets noobs <a href="https://kingdom-darkwebmarket.com/ ">darknet dream market link </a> https://kingdom-darkmarketplace.com/ - what darknet markets are still open
名前
Timothylen
versus project link <a href="https://darkwebkingdom.com/ ">best onion sites 2023 </a> https://kingdom-onion.com/ - new darknet markets
名前
Everettmus
blackweb darknet market <a href="https://kingdom-darkmarket-online.com/ ">dark web link </a> https://kingdom-darkmarket-online.com/ - cypher darknet market
名前
Robertzeque
site onion liste <a href="https://heinekendarkweb.com/ ">dark web links 2023 reddit </a> https://heinekendarkweb.com/ - darknet paypal accounts
名前
Williamroubs
dark markets usa <a href="https://kingdom-darkmarket.com/ ">darknet market links buy ssn </a> https://kingdom-darkmarket.com/ - black market websites tor
名前
WilliamUttep
buds express <a href="https://heineken-marketplace.com/ ">dark markets san marino </a> https://heinekenmarketplace24.com/ - where to find darknet market links redit
名前
CharlieZoose
darknet market links reddit <a href="https://drkingdommarket.com/ ">best working darknet market 2023 </a> https://drkingdommarket.com/ - buy darknet market email address
名前
RichardIcott
black market online <a href="https://kingdomdrugsmarket.com/ ">darknet market links 2023 reddit </a> https://kingdomdrugsmarketplace.com/ - darknet market busts
名前
ScottAduch
dark markets finland <a href="https://darkmarketkingdom.com/ ">top 10 dark websites </a> https://darkmarketkingdom.com/ - onion market url
名前
Allenthuck
darknet best drugs <a href="https://kingdomdrugsonline.com/ ">drugs dark web </a> https://kingdomdrugsonline.com/ - asap url
名前
Ronaldwrope
how to find the black market online <a href="https://heinekendarknetmarket.com/ ">best darknet drug sites </a> https://heinekenmarketdarknet.com/ - darknet market steroids
名前
EdwardHal
darknet market list 2023 <a href="https://kingdommarket-links.com/ ">dark markets ukraine </a> https://kingdommarket-links.com/ - dark websites
名前
JamesMop
reddit onion list <a href="https://heinekenmarket-darknet.com/ ">darknet сайты список </a> https://heineken-markett.com/ - darknet market oz
名前
Williammulge
weed only darknet market <a href="https://darkmarketheineken.com/ ">darknet drugs germany </a> https://darkmarketheineken.com/ - urls for darknet markets
名前
Zacharywah
duckduckgo dark web search <a href="https://kingdom-drugsonline.com/ ">darknet market bust </a> https://kingdom-drugsonline.com/ - best darknet drug sites
名前
Albertobut
how to buy from darknet markets <a href="https://kingdomdarkmarket.com/ ">what darknet markets sell fentanyl </a> https://kingdommarket-online.com/ - Cocorico link
名前
Davidinton
tma drug <a href="https://darkmarket-kingdom.com/ ">darknet drugs guide </a> https://darkmarket-kingdom.com/ - darknet adressen
名前
HenryHap
cheapest drugs on darknet <a href="https://heinekenexpressonion.com/ ">darknet market alaska </a> https://heineken-onion.com/ - versus project market url
名前
DavidLeape

コメントを追加

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