얼렁뚱땅코드/그누보드

즐겨찾기 태그 넣기

얼렁뚱땅 디자이너 2020. 11. 25. 15:05
<script>
$(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 &lt; 23
        window.sidebar.addPanel(bookmarkTitle,
			bookmarkURL,
			'');
		}else if ((window.sidebar && (navigator.userAgent.toLowerCase().indexOf('firefox') < -1)) || (window.opera && window.print)) {
			// Firefox version &gt;= 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;
	});
});
</script>
<a href="#" id="favorite" title="즐겨찾기 등록">
	이미지 또는 텍스트
</a>