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

カテゴリー

コメント

cypher market darknet <a href="https://heinekendarkmarketonline.com/ ">archetyp url </a> https://heineken-darkmarket-online.com/ - black market drugs
名前
EdwardOppow
darknet market arrests <a href="https://heinekenmarketonlinee.com/ ">darknet markets reddit </a> https://heinekenn-express.com/ - dnm xanax
名前
EdwardDride
darknet market lists <a href="https://darkfox-onlinedrugs.com/ ">deep dot web markets </a> https://darkfox-onlinedrugs.com/ - hitman for hire dark web
名前
Baaket
how to get on the dark web <a href="https://darkmarketheineken.com/ ">buying drugs online </a> https://darkmarketheineken.com/ - deep web software market
名前
Zacharywah
Heineken Express darknet <a href="https://darkfoxonlinedrugs.com/ ">new darknet markets 2023 </a> https://darkfoxonionmarket.com/ - dark web shopping
名前
Davidven
darknet markets reddit <a href="https://kingdom-darkmarket.com/ ">tor markets 2023 </a> https://kingdomdarkwebmarket.com/ - versus link
名前
WilliamUttep
darknet guide <a href="https://dark-web-kingdom.com/ ">archetyp darknet market </a> https://dark-web-kingdom.com/ - onion link search engine
名前
HenryHap
Kingdom link <a href="https://kingdom-onlinedrugs.com/ ">tor market </a> https://kingdom-onlinedrugs.com/ - Kingdom Market darknet
名前
Jimmyrox
darknet market google <a href="https://kingdom-darknet-drugstore.com/ ">deep dark web markets links </a> https://kingdom-darknet-drugstore.com/ - brick market
名前
DarrenMic
deep web canada <a href="https://heinekenmarket-online.com/ ">tor market nz </a> https://heinekendarkmarket.com/ - carding deep web links
名前
EugeneGor
darknet market dmt <a href="https://darkfox-onion-darkweb.com/ ">darknet database market </a> https://darkfox-onion-darkweb.com/ - darknet escrow markets
名前
Jeromesob
active darknet markets 2023 <a href="https://heineken-onion.com/ ">darknet drug prices </a> https://heineken-onion.com/ - darknet websites wiki
名前
DavidLeape
bohemia link <a href="https://heineken-express-onion.com/ ">darknet market noobs </a> https://heineken-express-onion.com/ - tor market
名前
Andrewbem
buy drugs from darknet <a href="https://heineken-dark-market.com/ ">dread onion </a> https://heinekendarkmarketplace.com/ - darknet market carding
名前
RandyEduts
darkfox url <a href="https://drkingdommarket.com/ ">dark web cvv </a> https://kingdommarketonlinee.com/ - what darknet markets are still open
名前
RichardIcott
best darknet market australia <a href="https://darkfoxdarkwebdrugstore.com/ ">dark markets san marino </a> https://darkfoxdarkwebdrugstore.com/ - Kingdom url
名前
AlbertGlice
darknet drug dealer <a href="https://heinekenmarketplacee.com/ ">dark markets liechtenstein </a> https://heinekenmarketplacee.com/ - sichere darknet markets 2023
名前
MichaelJet
dark markets united kingdom <a href="https://darkmarket-heineken.com/ ">darknet market pills vendor </a> https://darkmarket-heineken.com/ - best dark web marketplaces 2023
名前
DanielNoubs
online black market electronics <a href="https://heineken-darknet.com/ ">orange sunshine pill </a> https://heineken-darknet.com/ - weed darknet market
名前
Arnoldinfop
how to access darknet markets <a href="https://heinekenmarketplace24.com/ ">drugs dark web </a> https://heinekenmarketplace24.com/ - deep web canada
名前
CharlieZoose
updated darknet market links 2023 <a href="https://darkfoxdarknetdrugstore.com/ ">dark markets paraguay </a> https://darkfoxdarknetdrugstore.com/ - darknet sites url
名前
Stanleymet
darknet markets norge <a href="https://kingdommarket-online.com/ ">onion links credit card </a> https://kingdommarket-online.com/ - r darknet market
名前
Davidinton
reddit biggest darknet market place <a href="https://kingdom-darkmarketplace.com/ ">darknet markets 2023 reddit </a> https://kingdom-darkmarketplace.com/ - how to buy from darknet markets
名前
Timothylen
buying credit cards on dark web <a href="https://kingdom-online-drugs.com/ ">illegal black market </a> https://kingdom-online-drugs.com/ - biggest darknet market 2023
名前
BillyNut
versus darknet market <a href="https://darkweb-kingdom.com/ ">dark web sites name list </a> https://dark-market-kingdom.com/ - how to use deep web on pc
名前
BrettUttep
accessing darknet market <a href="https://heinekendarkwebmarket.com/ ">best darknet market may 2023 reddit </a> https://heinekendarkwebmarket.com/ - darknet drug vendors
名前
WillisVow
legit darknet sites <a href="https://heinekenmarketdarknet.com/ ">darknet onion markets </a> https://heinekenmarketdarknet.com/ - deep dark web
名前
EdwardHal
incognito market url <a href="https://heineken-darkmarketplace.com/ ">black market reddit </a> https://heineken-darkmarketplace.com/ - best deep web markets
名前
Phillipget
dark markets luxembourg <a href="https://heinekenmarket-url.com/ ">cypher market url </a> https://heinekenmarket-url.com/ - tor link list 2023
名前
Wesleyenuse
deep web market links reddit <a href="https://heinekenmarket-darknet.com/ ">dark markets uk </a> https://heinekenmarket-darknet.com/ - darkfox market link
名前
Williammulge
darknet market reddit list <a href="https://kingdomdarkmarketonline.com/ ">best darknet market for psychedelics </a> https://kingdom-darkmarket-online.com/ - reddit darknet market 2023
名前
Robertzeque
reddit darknet market deals <a href="https://kingdom-dark-market.com/ ">darknet database market </a> - deep web onion url
名前
Ronaldtic
darknet online drugs <a href="https://kingdomoniondarkweb.com/ ">dark markets india </a> https://kingdomoniondarkweb.com/ - Heineken Express darknet
名前
WesleyPex
darknet market francais <a href="https://kingdomdrugsmarketplace.com/ ">darknet dream market reddit </a> https://kingdomdrugsmarketplace.com/ - dark web cheap electronics
名前
ScottAduch
bitcoin dark website <a href="https://kingdomonlinedrugs.com/ ">the armory tor url </a> https://kingdomonlinedrugs.com/ - darknet markets australia
名前
Ronaldwrope
link darknet market <a href="https://kingdom-onion-darkmarket.com/ ">how to buy drugs on the darknet </a> https://kingdom-onion-market.com/ - dark markets czech republic
名前
JamesGal
back market trustworthy <a href="https://heinekenmarketurl.com/ ">dark market link </a> https://heinekenmarketurl.com/ - darknet drug markets reddit
名前
AndrewTelve
dark net markets <a href="https://darkmarketkingdom.com/ ">darknet market security </a> https://kingdomonion.com/ - back market legit
名前
Allenthuck
cypher market <a href="https://kingdomdarknet.com/ ">berlin telegram group drugs </a> https://kingdomdarkweb.com/ - tor market links
名前
ElmerPralt
orange sunshine pill <a href="https://kingdom-darknet.com/ ">darknetlive </a> https://kingdom-darknet.com/ - Abacus darknet Market
名前
DevinImMek
darknet links 2023 drugs <a href="https://kingdom-onion.com/ ">bohemia market darknet </a> https://kingdom-onion.com/ - dark markets norge
名前
Everettmus
dark web payment methods <a href="https://kingdom-drugsonline.com/ ">lsd drug wiki </a> https://kingdom-drugs-market.com/ - archetyp market url
名前
Albertobut
outlaw darknet market url <a href="https://kingdom-onion-darkweb.com/ ">deep web drug store </a> https://kingdom-onion-darkweb.com/ - top onion links
名前
IgnacioVorge
darknet links 2023 drugs <a href="https://drheinekenexpress.com/ ">grey market darknet </a> https://heinekennexpress.com/ - dark web step by step
名前
ErnestHalry
dark web drugs ireland <a href="https://heinekenn-express.com/ ">hacking tools darknet markets </a> https://heinekenmarketonlinee.com/ - legit darknet markets 2023
名前
EdwardDride
red ferrari pills <a href="https://heineken-darkmarket-online.com/ ">darknet selling drugs </a> https://heineken-darkmarket-online.com/ - current darknet market list
名前
EdwardOppow
darknet market adderall <a href="https://kingdomdarkwebmarket.com/ ">buds express </a> https://kingdomdarkwebmarket.com/ - darknet market news
名前
WilliamUttep
how to get to the black market online <a href="https://kingdommarketplacee.com/ ">onion live links </a> https://kingdommarketplacee.com/ - darknet market links 2023 reddit
名前
Baaket
dark web sites name list <a href="https://darkmarket-kingdom.com/ ">darknet drug links </a> https://dark-web-kingdom.com/ - darknet markets reddit
名前
HenryHap
pill with crown on it <a href="https://kingdom-onlinedrugs.com/ ">dark web sites for drugs </a> https://kingdom-onlinedrugs.com/ - dark web markets 2023
名前
Jimmyrox

コメントを追加

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