현재 접속한 브라우저를 확인 한다. 자세한 내용은 JS에서 다루고
해당 카테고리에서는 코드만 적어 놓으려고 합니다.
간단하게
var _browserState = 'unknown';
(function checkBrowser(){
var agent = navigator.userAgent.toLowerCase();
if(agent.indexOf("chrome")!=-1){_browserState="Chrome";}
else if(agent.indexOf("safari")!=-1){_browserState="safari";}
else if(agent.indexOf("firefox")!=-1){_browserState="firefox";}
else if(agent.indexOf("msie")!=-1 || agent.indexOf('trident')!=-1){_browserState="IE"}
for(let i=0;i<5;i++){ console.warn("connected Browser is "+_browserState);}
})();
// Extension Download reProduction Code
var _downloadEx = function(filename,contents){
if(_browserState.toLowerCase() ==='chrome'){
var element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(contents));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
//not in Chrome
else{
var a = document.createElement("a"),
file = new Blob([contents], { type: "text/plain;charset=utf-8" });
if (window.navigator.msSaveOrOpenBlob) // IE10+
window.navigator.msSaveOrOpenBlob(file, filename);
else { // Others
var url = URL.createObjectURL(file);
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
setTimeout(function () {
document.body.removeChild(a);
window.URL.revokeObjectURL(url);
}, 0);
}
}
}