【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 markets japan <a href="https://kingdom-darknet.com/ ">dark web uk </a> https://kingdom-darknet.com/ - tor search onion link
名前
Granttromo
biggest darknet market 2023 <a href="https://dark-market-heineken.com/ ">darknet список сайтов </a> https://dark-market-heineken.com/ - dark markets netherlands
名前
Matthewgek
best darknet market for weed uk <a href="https://heineken-drugs-online.com/ ">list of dark net markets </a> https://heineken-drugs-online.com/ - darknet market links reddit
名前
Michaelloush
darknet search engine url <a href="https://darkfox-onion-darkweb.com/ ">cheap darknet websites dor drugs </a> https://darkfox-onion-darkweb.com/ - wired darknet markets
名前
WilliamRip
gray market place <a href="https://kingdomdrugsmarketplace.com/ ">reliable darknet markets lsd </a> https://kingdomdrugsmarketplace.com/ - currently darknet markets
名前
Sirket
buy drugs online darknet <a href="https://heinekendarkmarketplace.com/ ">deep web cc sites </a> https://heineken-dark-market.com/ - dark web links reddit
名前
TimmyMeexy
dark markets 2023 <a href="https://dark-web-kingdom.com/ ">what darknet markets are available </a> https://darkmarket-kingdom.com/ - biggest darknet market 2023
名前
Danielred
buy bank accounts darknet <a href="https://heinekendarknetdrugstore.com/ ">legit darknet markets 2023 </a> https://heineken-onion-darkweb.com/ - darknet markets onion address
名前
RichardDek
dark market onion <a href="https://heineken-markett.com/ ">cypher market </a> https://heineken-markett.com/ - counterfeit money onion
名前
JamesseM
darknet drugs malayisa <a href="https://heineken-darkmarketplace.com/ ">what darknet markets still work </a> https://heineken-darkwebmarket.com/ - deep web websites reddit
名前
JasonGribe
red ferrari pills <a href="https://kingdom-onion-darkweb.com/ ">alphabay market darknet </a> https://kingdom-onion-darkweb.com/ - best drug darknet
名前
Geraldhopay
archetyp url <a href="https://kingdomonionmarket.com/ ">reddit darknet markets uk </a> https://kingdom-online-drugs.com/ - darknet drug markets 2023
名前
Ronaldevica
tor market links 2023 <a href="https://kingdom-dark-market.com/ ">vice city market </a> https://kingdom-dark-market.com/ - best darknet drug sites
名前
Ralphzet
black market prescription drugs <a href="https://kingdom-darkmarket-online.com/ ">top darknet markets 2023 </a> https://kingdomdarkmarketonline.com/ - dark markets denmark
名前
CharlesNuh
grey market darknet link <a href="https://kingdom-drugs-market.com/ ">best darknet market 2023 </a> https://kingdom-drugsonline.com/ - dark web markets reddit
名前
WilliamNaw
dark web drugs ireland <a href="https://heinekenoniondarkweb.com/ ">darknet market </a> https://heinekenoniondarkweb.com/ - how big is the darknet market
名前
RobertKix
uncensored hidden wiki link <a href="https://darkfoxdarknetdrugstore.com/ ">what is darknet markets </a> https://darkfoxdarknetdrugstore.com/ - deep web cc dumps
名前
Crisscunc
reddit darknet market australia <a href="https://heinekendrugsonline.com/ ">how to get on the dark web android </a> https://heinekendrugsonline.com/ - darkfox darknet market
名前
Stevejails
dark web drug markets <a href="https://dark-market-kingdom.com/ ">reddit darknet market list 2023 </a> https://dark-market-kingdom.com/ - dark web hitmen
名前
Teddred
dark markets mexico <a href="https://heinekenmarket-url.com/ ">how big is the darknet market </a> https://heinekenmarketlink.com/ - darknet drug market
名前
BrandonWaype
monkey xtc pill <a href="https://kingdom-onion-darkmarket.com/ ">dark web links 2023 </a> https://kingdom-onion-market.com/ - drugs on the darknet
名前
DamonLat
how to use darknet markets <a href="https://heineken-darkweb.com/ ">adress darknet </a> https://heineken-darkweb.com/ - darknet markets reddit links
名前
Michaeltus
assassination market darknet <a href="https://heinekenmarketurl.com/ ">reddit darknet market guide </a> https://heinekenurl.com/ - Abacus link
名前
Charlescob
top 10 dark websites <a href="https://kingdommarket-online.com/ ">black market websites tor </a> https://kingdommarket-online.com/ - tor market nz
名前
Hanstulge
url hidden wiki <a href="https://heinekenonionmarket.com/ ">deep web url links </a> https://heineken-online-drugs.com/ - shop ccs carding
名前
Edgarlow
dark web poison <a href="https://heineken-drugs-market.com/ ">superman pills mg </a> https://heineken-drugsonline.com/ - superman pills mg
名前
Brandendet
deep web marketplaces reddit <a href="https://heinekendarkwebdrugstore.com/ ">hidden marketplace </a> https://heineken-darknet-drugstore.com/ - underground market online
名前
HectorDer
darknet drug dealer <a href="https://darkmarketkingdom.com/ ">live darknet markets </a> https://kingdomonion.com/ - alphabay url
名前
FrankHuluh
adress darknet <a href="https://heinekenmarket-link.com/ ">live onion market </a> https://heinekenmarket-links.com/ - dark markets latvia
名前
Robertfup
top darknet market 2023 <a href="https://heinekendarkmarket.com/ ">deep dot web markets </a> https://heinekenmarket-online.com/ - drug market darknet
名前
DavidDes
black market deep <a href="https://kingdomdarkweb.com/ ">buying drugs on darknet </a> https://kingdomdarkweb.com/ - how to get on the dark web android
名前
JamesHub
drugs sold on dark web <a href="https://dark-web-heineken.com/ ">darknet escrow </a> https://dark-web-heineken.com/ - asap link
名前
HaroldHot
uncensored deep web <a href="https://drheinekenexpress.com/ ">dark chart </a> https://heinekennexpress.com/ - wikipedia darknet market
名前
Richardvak
uncensored hidden wiki link <a href="https://darkwebkingdom.com/ ">darkmarket </a> https://darkwebkingdom.com/ - active darknetmarkets
名前
Danired
darknet market sites <a href="https://kingdomdarkwebdrugstore.com/ ">dark market link </a> https://kingdomdarkwebdrugstore.com/ - darknet market links
名前
Julianacecy
nursing school program <a href="https://schoolnursingesse.com/">case management nursing definition</a> medical surgical nursing assessment and management of clinical problems 9th edition pdf
名前
tiendy
drug market <a href="https://heineken-onion.com/ ">deepdotweb markets </a> https://heineken-onion.com/ - how to access the black market
名前
Dannyquord
redit safe darknet markets <a href="https://darkfox-onion-darkmarket.com/ ">where to find darknet market links redit </a> https://darkfox-onion-darkmarket.com/ - darknet illegal market
名前
Jancal
dark markets moldova <a href="https://kingdommarketdarknet.com/ ">darknet drug vendors </a> https://kingdommarketdarknet.com/ - deep web search engine 2023
名前
Tornaddib
vice city link <a href="https://kingdommarket-url.com/ ">0day onion </a> - phenylethylamine
名前
ADElugh
bohemia market <a href="https://heinekenmarketdarknet.com/ ">black market illegal drugs </a> https://heinekendarknetmarket.com/ - how to browse the dark web reddit
名前
Josephanarm
asap url <a href="https://darkfoxonionmarket.com/ ">blue lady e pill </a> https://darkfoxonlinedrugs.com/ - top onion links
名前
Davidinodo
incognito url <a href="https://kingdommarketurl.com/ ">buy bank accounts darknet </a> https://kingdommarketurl.com/ - decabol pills
名前
Hellyzes
deep sea darknet market <a href="https://heinekendrugsmarket.com/ ">dread onion </a> https://heinekendrugsmarketplace.com/ - deep onion links
名前
MichaelRaf
reddit where to buy drugs <a href="https://kingdommarket-links.com/ ">buying drugs off darknet </a> https://kingdommarket-links.com/ - agora darknet market
名前
CorryViarD
dark web hitmen <a href="https://kingdom-darkmarket.com/ ">tor darknet market address </a> https://kingdom-darkmarket.com/ - cannabis dark web
名前
Wendellpog
deep web links reddit <a href="https://kingdom-drugs-online.com/ ">dark markets malaysia </a> https://kingdom-onlinedrugs.com/ - deepdotweb markets
名前
Shanewat
how to buy from the darknet markets lsd <a href="https://heinekenmarketonlinee.com/ ">tor search onion link </a> https://heinekenmarketonlinee.com/ - xanax darknet reddit
名前
Patrickhuple
darknet market google <a href="https://kingdom-darkmarketplace.com/ ">onion market url </a> https://kingdom-darkwebmarket.com/ - darknet drug markets 2023
名前
JamesStaiz
cvv black market <a href="https://heineken-express-onion.com/ ">darknet markets 2023 reddit </a> https://heineken-express-onion.com/ - what darknet markets are up
名前
BrianFew

コメントを追加

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