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

カテゴリー

コメント

wiki darknet market <a href="https://kingdomdrugsonline.com/ ">deep market </a> https://kingdomdrugsonline.com/ - fresh onions link
名前
Davidjoisp
hidden marketplace <a href="https://heineken-darkmarket-online.com/ ">dark web electronics </a> https://heinekendarkmarketonline.com/ - darknet bitcoin market
名前
Randykew
darknet software market <a href="https://kingdomoniondarkweb.com/ ">darknet search </a> https://kingdomoniondarkmarket.com/ - darknet drug vendor that takes paypal
名前
CraigAgeni
darknet links markets <a href="https://heinekendarkwebmarket.com/ ">darkmarket </a> https://heineken-darkmarket.com/ - archetyp url
名前
DonaldDic
darknet market links safe <a href="https://heineken-onion-darkmarket.com/ ">deep cp links </a> https://heineken-onion-market.com/ - black market prices for drugs
名前
JackieDuart
drugs on the deep web <a href="https://darkweb-heineken.com/ ">dark web search tool </a> https://dark-market-heineken.com/ - nike jordan pill
名前
Matthewgek
the dark web url <a href="https://kingdom-darknet.com/ ">darknet markets onion address </a> https://kingdom-darkweb.com/ - what are darknet drug markets
名前
Granttromo
darknet market package <a href="https://kingdommarketplacee.com/ ">superman pills mg </a> https://kingdommarketplacee.com/ - gray market place
名前
Baaket
top 10 dark websites <a href="https://heinekenmarketplacee.com/ ">darkweb sites reddit </a> https://kingdom-darkweb-drugstore.com/ - legit darknet sites
名前
Randytiz
how to access the dark web 2023 <a href="https://heineken-dark-market.com/ ">dark markets philippines </a> https://heineken-dark-market.com/ - darknet market get pills
名前
TimmyMeexy
darknet market list 2023 <a href="https://kingdomdrugsmarketplace.com/ ">shop valid cvv </a> https://kingdomdrugsmarketplace.com/ - dread onion
名前
Sirket
best fraud market darknet <a href="https://heineken-markett.com/ ">dark markets france </a> https://heineken-markett.com/ - how to buy from the darknet markets
名前
JamesseM
best darknet market australia <a href="https://kingdomdarknetdrugstore.com/ ">what are darknet drug markets </a> https://kingdom-onion-darkweb.com/ - online onion market
名前
Geraldhopay
red ferrari pills <a href="https://heineken-darkwebmarket.com/ ">darknet union </a> https://heineken-darkmarketplace.com/ - how to access the dark web through tor
名前
JasonGribe
how to access the dark web reddit <a href="https://kingdom-dark-market.com/ ">reddit darknet markets 2023 </a> https://kingdom-dark-market.com/ - dark markets turkey
名前
Ralphzet
alphabay darknet market <a href="https://kingdom-darkmarket-online.com/ ">google black market </a> https://kingdomdarkmarketonline.com/ - darknet wiki link
名前
CharlesNuh
black market websites 2023 <a href="https://heineken-onion-darkweb.com/ ">deep web drug url </a> https://heinekendarknetdrugstore.com/ - history of darknet markets
名前
RichardDek
exploit market darknet <a href="https://heineken-onlinedrugs.com/ ">dark web drugs </a> https://heineken-onlinedrugs.com/ - darkfox market link
名前
Michaelloush
darknet market script <a href="https://kingdomonionmarket.com/ ">deep web links reddit </a> https://kingdom-online-drugs.com/ - dark markets norge
名前
Ronaldevica
onion live <a href="https://heinekenmarketlink.com/ ">deep dark web markets links </a> https://heinekenmarketlink.com/ - darknet buy drugs
名前
BrandonWaype
deep dark web markets links <a href="https://kingdom-drugsonline.com/ ">darkmarket list </a> https://kingdom-drugsonline.com/ - tor2door link
名前
WilliamNaw
black market website <a href="https://kingdom-onion-darkmarket.com/ ">list of darknet drug markets </a> https://kingdom-onion-market.com/ - dark markets new zealand
名前
DamonLat
onion market url <a href="https://heineken-darkweb.com/ ">cheap darknet websites dor drugs </a> https://heineken-darknet.com/ - darknet market bible
名前
Michaeltus
darknet market superlist <a href="https://heinekenmarketurl.com/ ">darknet market package </a> https://heinekenurl.com/ - deep web search engine 2023
名前
Charlescob
link de hiden wiki <a href="https://heinekenonlinedrugs.com/ ">which darknet markets are still open </a> https://heinekendrugsonline.com/ - uncensored hidden wiki link
名前
Stevejails
darknet drugs australia <a href="https://heinekendarkmarket.com/ ">darknet best drugs </a> https://heinekendarkmarket.com/ - best websites dark web
名前
DavidDes
dark web uk <a href="https://heinekenmarket-links.com/ ">onion marketplace drugs </a> https://heinekenmarket-link.com/ - largest darknet market
名前
Robertfup
darknet credit card market <a href="https://heinekenoniondarkweb.com/ ">dark web login guide </a> https://heinekenoniondarkmarket.com/ - black market website legit
名前
RobertKix
darkweb market <a href="https://darkmarket-kingdom.com/ ">deep market </a> https://darkmarket-kingdom.com/ - how to install deep web
名前
Danielred
cypher market url <a href="https://kingdomdarkmarket.com/ ">onion directory list </a> https://kingdomdarkmarket.com/ - dark markets indonesia
名前
Hanstulge
deep dark web <a href="https://darkmarket-heineken.com/ ">dark markets montenegro </a> https://dark-web-heineken.com/ - dark markets south korea
名前
HaroldHot
dark web drugs nz <a href="https://heineken-onion.com/ ">underground market online </a> https://heineken-onion.com/ - darknet market reddit 2023
名前
Dannyquord
dark web sales <a href="https://heineken-drugsonline.com/ ">deep web drug prices </a> https://heineken-drugsonline.com/ - deep dot web links
名前
Brandendet
darknet markets most popular <a href="https://drheinekenexpress.com/ ">best darknet market links </a> https://heinekennexpress.com/ - buying darknet drugs
名前
Richardvak
how to buy drugs on the darknet <a href="https://kingdom-darknet-drugstore.com/ ">dark web drug marketplace </a> https://kingdomdarkwebdrugstore.com/ - darknet market sites
名前
Julianacecy
how to access the darknet market <a href="https://heinekendarknetmarket.com/ ">working darknet market links </a> https://heinekendarknetmarket.com/ - darknet market ddos
名前
Josephanarm
alphabay market darknet <a href="https://darkmarketkingdom.com/ ">darknet markets still open </a> https://kingdomonion.com/ - dark markets china
名前
FrankHuluh
market street darknet <a href="https://heinekenonionmarket.com/ ">deep web links reddit </a> https://heinekenonionmarket.com/ - darknet black market
名前
Edgarlow
underground black market website <a href="https://kingdomurl.com/ ">ethereum darknet markets </a> https://kingdomurl.com/ - how to search the dark web reddit
名前
Hellyzes
dark markets canada <a href="https://kingdommarket-darknet.com/ ">reddit darknet markets links </a> https://kingdommarket-darknet.com/ - darknet website for drugs
名前
CorryViarD
darknet black market url <a href="https://darkweb-kingdom.com/ ">darknet market buying mdma usa </a> [url=https://darkweb-kingdom.com/ ]dark markets canada [/url]
名前
Teddred
darknet market news <a href="https://kingdom-darkmarket.com/ ">dark web markets 2023 australia </a> https://kingdom-darkmarket.com/ - deep web updated links
名前
Wendellpog
australian darknet vendors <a href="https://kingdom-drugs-online.com/ ">reddit darknet market noobs bible </a> https://kingdom-onlinedrugs.com/ - dark web sites drugs
名前
Shanewat
darknet markets australia <a href="https://heinekendarkweb.com/ ">darknet markets list 2023 </a> https://heinekendarknet.com/ - darknet market francais
名前
JuliusEsobe
vice city darknet market <a href="https://heinekendarkwebdrugstore.com/ ">nike jordan pill </a> https://heineken-darknet-drugstore.com/ - dark web search engines link
名前
HectorDer
cp links dark web <a href="https://heineken-express-onion.com/ ">darknet market url list </a> https://darkwebheineken.com/ - cypher darknet market
名前
BrianFew
best website to buy cc <a href="https://heinekenn-express.com/ ">Cocorico Market </a> https://heinekenmarketonlinee.com/ - Kingdom link
名前
Patrickhuple
best onion sites 2023 <a href="https://kingdommarket-url.com/ ">current darknet market list </a> - dream market darknet
名前
ADElugh
adress darknet <a href="https://darkfoxonlinedrugs.com/ ">darknet drugs sales </a> https://darkfoxonlinedrugs.com/ - how to enter the black market online
名前
Davidinodo
dark markets san marino <a href="https://kingdom-darkmarketplace.com/ ">top darknet markets 2023 </a> https://kingdom-darkwebmarket.com/ - dark web markets reddit
名前
JamesStaiz

コメントを追加

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