【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 web market list <a href="https://darkmarketheineken.com/ ">cheap darknet websites dor drugs </a> https://darkmarketheineken.com/ - tor markets links
名前
ZacharyBop
counterfeit euro deep web <a href="https://kingdom-darkmarket.com/ ">site darknet fermГ© </a> https://kingdomdarkwebmarket.com/ - best onion sites 2023
名前
Wendellpog
most popular darknet markets 2023 <a href="https://kingdom-drugs-online.com/ ">darknet market noobs bible </a> https://kingdom-onlinedrugs.com/ - dark market link
名前
Shanewat
carding dark web <a href="https://heineken-express-onion.com/ ">darknet guide </a> https://darkwebheineken.com/ - 2023 working darknet market
名前
BrianFew
dark markets poland <a href="https://heinekenonionmarket.com/ ">dark market link </a> https://heineken-online-drugs.com/ - weed only darknet market
名前
Edgarlow
darknet market controlled delivery <a href="https://kingdommarketlink.com/ ">tor websites reddit </a> - dark markets macedonia
名前
ADElugh
best dark web links <a href="https://heinekendrugsmarket.com/ ">darknet market links </a> https://heinekendrugsmarket.com/ - dark web steroids
名前
MichaelRaf
darknet market onions <a href="https://heinekendarkwebdrugstore.com/ ">darknet drug market </a> https://heinekendarkwebdrugstore.com/ - list of online darknet market
名前
HectorDer
incognito darknet market <a href="https://heinekenmarketonlinee.com/ ">black market website names </a> https://heinekenmarketonlinee.com/ - dark markets germany
名前
Patrickhuple
black market websites credit cards <a href="https://heineken-marketplace.com/ ">how to install deep web </a> https://heineken-marketplace.com/ - darknet list
名前
Georgelouse
best darknet market australia <a href="https://darkmarket-kingdom.com/ ">counterfeit money dark web reddit </a> https://darkmarket-kingdom.com/ - trusted darknet markets weed
名前
Danielred
darknet litecoin <a href="https://kingdom-darkwebmarket.com/ ">deep web updated links </a> https://kingdom-darkwebmarket.com/ - dark net guide
名前
JamesStaiz
reddit biggest darknet market place <a href="https://kingdom-darknet-drugstore.com/ ">what darknet markets are still open </a> https://kingdom-darknet-drugstore.com/ - drug market
名前
Julianacecy
Kingdom link <a href="https://kingdommarketonlinee.com/ ">blackweb darknet market </a> https://drkingdommarket.com/ - active darknet market urls
名前
SmittMef
how to access deep web safely reddit <a href="https://heinekendarkmarketonline.com/ ">australian dark web markets </a> https://heineken-darkmarket-online.com/ - best dark web markets 2023
名前
Randykew
dark web website links <a href="https://kingdomdrugsonline.com/ ">what is the darknet market </a> https://kingdomdrugsonline.com/ - darkweb market
名前
Davidjoisp
what darknet markets are open <a href="https://kingdomoniondarkmarket.com/ ">deep web canada </a> https://kingdomoniondarkweb.com/ - dxm pills
名前
CraigAgeni
dark web links market <a href="https://dark-market-heineken.com/ ">best darknet markets for vendors </a> https://darkweb-heineken.com/ - what darknet markets are live
名前
Matthewgek
darknet markets 2023 <a href="https://heineken-darkmarket.com/ ">drug website dark web </a> https://heineken-darkmarket.com/ - credit card dark web links
名前
DonaldDic
guns dark market <a href="https://kingdom-darknet.com/ ">adresse onion </a> https://kingdom-darkweb.com/ - dark web sites xxx
名前
Granttromo
we amsterdam <a href="https://heineken-onion-market.com/ ">top darknet drug sites </a> https://heineken-onion-market.com/ - hidden wiki tor onion urls directories
名前
JackieDuart
deep dot web markets <a href="https://heinekenmarketplacee.com/ ">dark web drug markets </a> https://kingdom-darkweb-drugstore.com/ - dark web address list
名前
Randytiz
best darknet market for heroin <a href="https://heineken-markett.com/ ">dark markets monaco </a> https://heinekenmarket-darknet.com/ - darknet drugs germany
名前
JamesseM
darknet buy drugs <a href="https://darkfoxonlinedrugs.com/ ">darkfox darknet market </a> https://darkfoxonionmarket.com/ - current darknet market list
名前
Davidinodo
reddit darknet market noobs bible <a href="https://dark-market-kingdom.com/ ">darknet websites list 2023 </a> https://darkweb-kingdom.com/ - darkfox market url
名前
Teddred
onion linkek <a href="https://kingdomdrugsmarketplace.com/ ">darknet market onion links </a> https://kingdomdrugsmarket.com/ - best darknet market for guns
名前
Sirket
dot onion websites <a href="https://heineken-darkmarketplace.com/ ">dark chart </a> https://heineken-darkwebmarket.com/ - superlist darknet markets
名前
JasonGribe
dark web payment methods <a href="https://kingdomdarkmarketplace.com/ ">dark web sites links </a> https://kingdom-dark-market.com/ - versus project market url
名前
Ralphzet
onion market <a href="https://heinekenmarket-url.com/ ">cypher darknet market </a> https://heinekenmarketlink.com/ - darknet marketplace
名前
BrandonWaype
darknet market wiki <a href="https://kingdomdarkmarketonline.com/ ">how to access darknet market </a> https://kingdom-darkmarket-online.com/ - darknet market dash
名前
CharlesNuh
darkfox market <a href="https://heinekendarknetdrugstore.com/ ">best dark web search engine link </a> https://heinekendarknetdrugstore.com/ - dark markets liechtenstein
名前
RichardDek
dark markets new zealand <a href="https://kingdom-online-drugs.com/ ">dark web markets 2023 </a> https://kingdom-online-drugs.com/ - reddit darknet market list
名前
Ronaldevica
dark markets estonia <a href="https://heineken-onlinedrugs.com/ ">Kingdom link </a> https://heineken-onlinedrugs.com/ - how to anonymously use darknet markets
名前
Michaelloush
darknet market drug <a href="https://kingdom-drugsonline.com/ ">Cocorico darknet Market </a> https://kingdom-drugs-market.com/ - darknet markets florida
名前
WilliamNaw
bitcoin market on darknet tor <a href="https://heineken-darkweb.com/ ">dark web login guide </a> https://heineken-darkweb.com/ - darknet drug market list
名前
Michaeltus
dark web sites xxx <a href="https://heinekenmarketurl.com/ ">darknet drug vendor that takes paypal </a> https://heinekenmarketurl.com/ - buy bitcoin for dark web
名前
Charlescob
drugs sold on dark web <a href="https://heinekendrugsonline.com/ ">reddit darknet markets noobs </a> https://heinekenonlinedrugs.com/ - drugs dark web price
名前
Stevejails
darknet market onions <a href="https://kingdom-onion.com/ ">darknet list market </a> https://kingdom-onion.com/ - dark web links adult
名前
Danired
best darknet market for weed uk <a href="https://darkfox-onlinedrugs.com/ ">top darknet markets </a> https://kingdommarketplacee.com/ - how to create a darknet market
名前
Baaket
australian dark web vendors <a href="https://heinekenmarket-link.com/ ">Cocorico Market darknet </a> https://heinekenmarket-links.com/ - reddit darknet market list 2023
名前
Robertfup
market street darknet <a href="https://kingdomurl.com/ ">tor2door darknet market </a> https://kingdommarketurl.com/ - dark markets montenegro
名前
Hellyzes
best drug darknet <a href="https://kingdommarket-darknet.com/ ">working darknet market links </a> https://kingdommarket-links.com/ - drug market
名前
CorryViarD
dark markets korea <a href="https://kingdom-marketplace.com/ ">reddit best darknet market </a> https://kingdom-marketplace.com/ - best darknet market for counterfeit
名前
WilliamRip
onion directory <a href="https://darkfox-onion-darkmarket.com/ ">deep web drugs </a> https://darkfox-onion-darkmarket.com/ - sichere darknet markets 2023
名前
Jancal
best darknet market 2023 reddit <a href="https://kingdomdarknet.com/ ">best darknet market urs </a> https://kingdomdarknet.com/ - top dumps shop
名前
JamesHub
archetyp market <a href="https://kingdom-onion-darkweb.com/ ">florida darknet markets </a> https://kingdom-onion-darkweb.com/ - how to buy from darknet markets
名前
Geraldhopay
guide to darknet markets <a href="https://kingdom-markett.com/ ">monkey x pill </a> https://kingdommarketdarknet.com/ - buy drugs from darknet
名前
Tornaddib
redit safe darknet markets <a href="https://heinekenoniondarkmarket.com/ ">darknet market litecoin </a> https://heinekenoniondarkweb.com/ - deep web links 2023 reddit
名前
RobertKix
dark web drug markets <a href="https://darkmarket-heineken.com/ ">darknet drugs safe </a> https://darkmarket-heineken.com/ - adresse onion
名前
HaroldHot
deep web onion url <a href="https://heinekenexpressonion.com/ ">deep cp links </a> https://heinekenexpressonion.com/ - dark market url
名前
Dannyquord

コメントを追加

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