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

カテゴリー

コメント

what darknet market to use <a href="https://heineken-darkmarketplace.com/ ">darknet markets list 2023 </a> https://heineken-darkwebmarket.com/ - dark markets latvia
名前
JasonGribe
darknet black market sites <a href="https://darkweb-kingdom.com/ ">dark markets paraguay </a> https://dark-market-kingdom.com/ - darknet market francais
名前
Teddred
darknet markets address <a href="https://kingdomonionmarket.com/ ">darknet websites </a> https://kingdomonionmarket.com/ - Kingdom Market link
名前
Ronaldevica
darknet market deep dot web <a href="https://kingdom-dark-market.com/ ">black market prescription drugs for sale </a> https://kingdomdarkmarketplace.com/ - darknet drugs url
名前
Ralphzet
dark markets russia <a href="https://kingdom-darkmarket-online.com/ ">australian darknet vendors </a> https://kingdomdarkmarketonline.com/ - versus project market
名前
CharlesNuh
site onion liste <a href="https://kingdom-onion-market.com/ ">darknet market dash </a> https://kingdom-onion-darkmarket.com/ - australian dark web markets
名前
DamonLat
darknet union <a href="https://heinekenoniondarkmarket.com/ ">best lsd darknet market </a> https://heinekenoniondarkmarket.com/ - what darknet markets still work
名前
RobertKix
back market legit <a href="https://kingdom-drugsonline.com/ ">darknet market fake id </a> https://kingdom-drugsonline.com/ - best darknet marketplaces
名前
WilliamNaw
best dark web marketplaces 2023 <a href="https://heinekenonlinedrugs.com/ ">how to order from dark web </a> https://heinekenonlinedrugs.com/ - hire an assassin dark web
名前
Stevejails
tor market url <a href="https://kingdomdarknetmarket.com/ ">darknet cannabis markets </a> https://darkfoxdarknetdrugstore.com/ - darknet market noobs guide
名前
Crisscunc
dark markets norway <a href="https://heinekenmarketlink.com/ ">deep web search engines 2023 </a> https://heinekenmarketlink.com/ - dark websites
名前
BrandonWaype
dark markets malaysia <a href="https://kingdommarket-links.com/ ">superman pills mg </a> https://kingdommarket-links.com/ - buying drugs off darknet
名前
CorryViarD
what is escrow darknet markets <a href="https://heineken-darknet.com/ ">drugs dark web reddit </a> https://heineken-darkweb.com/ - black market website
名前
Michaeltus
darknet market links safe <a href="https://darkwebkingdom.com/ ">reddit darknet market guide </a> https://kingdom-onion.com/ - top darknet market 2023
名前
Danired
darknet market package <a href="https://heinekenurl.com/ ">deep website search engine </a> https://heinekenurl.com/ - darknet database market
名前
Charlescob
darknet markets availability <a href="https://kingdommarket-online.com/ ">how to browse the dark web reddit </a> https://kingdomdarkmarket.com/ - black market online website
名前
Hanstulge
tor best websites <a href="https://kingdom-darknet-drugstore.com/ ">reddit darknet markets uk </a> https://kingdomdarkwebdrugstore.com/ - dnm market
名前
Julianacecy
black market net <a href="https://heineken-online-drugs.com/ ">bitcoin market on darknet tor </a> https://heineken-online-drugs.com/ - dark market list
名前
Edgarlow
darknet sites <a href="https://heineken-drugsonline.com/ ">buying drugs online </a> https://heineken-drugsonline.com/ - grey market drugs
名前
Brandendet
links da deep web 2023 <a href="https://heineken-darknet-drugstore.com/ ">underground black market website </a> https://heinekendarkwebdrugstore.com/ - deep web drugs
名前
HectorDer
tor marketplaces <a href="https://darkfoxonionmarket.com/ ">darknet markets availability </a> https://darkfoxonionmarket.com/ - buying drugs online on openbazaar
名前
Davidinodo
black market deep <a href="https://darkmarketkingdom.com/ ">darknet drug vendor that takes paypal </a> https://kingdomonion.com/ - tor marketplace
名前
FrankHuluh
darknet list <a href="https://heinekenmarket-online.com/ ">best darknet markets 2023 </a> https://heinekenmarket-online.com/ - how to use the darknet markets
名前
DavidDes
dark web drugs australia <a href="https://dark-web-heineken.com/ ">asap market url </a> https://darkmarket-heineken.com/ - dark markets sweden
名前
HaroldHot
dark websites <a href="https://heinekenmarket-link.com/ ">cypher market url </a> https://heinekenmarket-link.com/ - deep web drug prices
名前
Robertfup
drug market <a href="https://kingdomdarknet.com/ ">market links darknet </a> https://kingdomdarknet.com/ - best darknet market for heroin
名前
JamesHub
dark markets chile <a href="https://drheinekenexpress.com/ ">2023 darknet market </a> https://heinekennexpress.com/ - where to find onion links
名前
Richardvak
dark market reddit <a href="https://kingdommarketlink.com/ ">darknet market place search </a> - safe darknet markets
名前
ADElugh
darknet credit card market <a href="https://heineken-onion.com/ ">list of dark net markets </a> https://heineken-onion.com/ - darknet database market
名前
Dannyquord
darknet market reddit list <a href="https://kingdomurl.com/ ">darknet market prices </a> https://kingdommarketurl.com/ - alphabay market
名前
Hellyzes
dark market reddit <a href="https://heinekendarknetmarket.com/ ">dark markets poland </a> https://heinekendarknetmarket.com/ - darknet market alaska
名前
Josephanarm
verified darknet market <a href="https://darkfoxdarkwebdrugstore.com/ ">buy ssn dob with bitcoin </a> https://darkfoxdarkwebdrugstore.com/ - onion links 2023
名前
Jancal
darknet market adressen <a href="https://kingdommarketdarknet.com/ ">buying drugs off darknet </a> https://kingdommarketdarknet.com/ - reddit best darknet markets
名前
Tornaddib
dark web uk <a href="https://darkmarketheineken.com/ ">dark websites reddit </a> https://heinekenonion.com/ - darknet market search
名前
ZacharyBop
dark markets new zealand <a href="https://heinekendrugsmarketplace.com/ ">wikipedia darknet market </a> https://heinekendrugsmarket.com/ - dark markets brazil
名前
MichaelRaf
deep dot web markets <a href="https://kingdom-onlinedrugs.com/ ">dark markets portugal </a> https://kingdom-onlinedrugs.com/ - darknet guide
名前
Shanewat
monero darknet market <a href="https://kingdomdarkwebmarket.com/ ">reddit where to buy drugs </a> https://kingdom-darkmarket.com/ - blue lady e pill
名前
Wendellpog
deep web shopping site <a href="https://heinekenmarketonlinee.com/ ">darknet markets 2023 </a> https://heinekenn-express.com/ - top ten dark web
名前
Patrickhuple
lsd drug wiki <a href="https://kingdom-darkwebmarket.com/ ">darkfox market link </a> https://kingdom-darkwebmarket.com/ - dark web electronics
名前
JamesStaiz
carding dark web <a href="https://darkwebheineken.com/ ">darknet websites drugs </a> https://heineken-express-onion.com/ - darknet market onion links
名前
BrianFew
tor market list <a href="https://heinekendarkweb.com/ ">onion links 2023 </a> https://heinekendarkweb.com/ - darknet drugs sales
名前
JuliusEsobe
deep web deb <a href="https://heineken-marketplace.com/ ">the onion directory </a> https://heinekenmarketplace24.com/ - we amsterdam
名前
Georgelouse
dark web sites <a href="https://heineken-onion-darkmarket.com/ ">how to darknet market </a> https://heineken-onion-darkmarket.com/ - buy drugs darknet
名前
JackieDuart
darknet market reddit <a href="https://drkingdommarket.com/ ">dark web markets 2023 australia </a> https://kingdommarketonlinee.com/ - the dark web links 2023
名前
SmittMef
reddit darknet markets noobs <a href="https://heineken-darkmarket-online.com/ ">best darknet market links </a> https://heinekendarkmarketonline.com/ - how to buy drugs dark web
名前
Randykew
best dark web counterfeit money <a href="https://kingdommarketplacee.com/ ">darknet market adderall </a> https://darkfox-onlinedrugs.com/ - uk darknet markets
名前
Baaket
the dark market <a href="https://kingdomoniondarkmarket.com/ ">legit onion sites </a> https://kingdomoniondarkmarket.com/ - darknet market lists
名前
CraigAgeni
incognito market link <a href="https://heinekendarkwebmarket.com/ ">darknet market steroids </a> https://heineken-darkmarket.com/ - dark markets sweden
名前
DonaldDic
darknet market lightning network <a href="https://kingdom-darkweb-drugstore.com/ ">grey market drugs </a> https://heinekenmarketplacee.com/ - access the dark web reddit
名前
Randytiz
darknet drugs <a href="https://kingdomonlinedrugs.com/ ">search darknet markets </a> https://kingdomonlinedrugs.com/ - darknet drugs 2023
名前
Davidjoisp

コメントを追加

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