$(document).ready(function() {
$('#favorite').on('click', function(e) {
var bookmarkURL = window.location.href;
var bookmarkTitle = document.title;
var triggerDefault = false;
if (window.sidebar && window.sidebar.addPanel) {
// Firefox version < 23
window.sidebar.addPanel(bookmarkTitle, bookmarkURL, '');
} else if ((window.sidebar && (navigator.userAgent.toLowerCase().indexOf('firefox') > -1)) || (window.opera && window.print)) {
// Firefox version >= 23 and Opera Hotlist
var $this = $(this);
$this.attr('href', bookmarkURL);
$this.attr('title', bookmarkTitle);
$this.attr('rel', 'sidebar');
$this.off(e);
triggerDefault = true;
} else if (window.external && ('AddFavorite' in window.external)) {
// IE Favorite
window.external.AddFavorite(bookmarkURL, bookmarkTitle);
} else { // WebKit - Safari/Chrome
alert((navigator.userAgent.toLowerCase().indexOf('mac') != -1 ? 'Cmd' : 'Ctrl') + '+D 키를 눌러 즐겨찾기에 등록하실 수 있습니다.');
}
return triggerDefault;
});
});
<a href="#" id="favorite"><img src="/image/top_add_btn2.gif" alt="즐겨찾기 추가"/></a>
'개발 이야기 > Javascript & jQuery' 카테고리의 다른 글
String.prototype.padStart() 기능 및 IE에서 실행하는법 (0) | 2020.04.29 |
---|---|
javascript 쿠키를 사용해서 스크롤 유지 (0) | 2020.03.26 |
PC or Mobile 접속 판별 소스 (0) | 2020.02.05 |
Event.isTrusted (0) | 2020.02.05 |
[JavaScript] 인쇄할 내용을 객체로 만들어서 프린트하기 (0) | 2020.01.30 |