[Javascript] 브라우저 즐겨찾기추가 스크립트

HYEONG HWAN, MUN/ 10월 18, 2014/ 미분류/ 0 comments

https://blog.lael.be/post/127

배경 

Javascript 로 브라우저가 지원하는 즐겨찾기추가 명령을 실행합니다.

이 기능은 Firefox, Opera, InternetExplorer 에서 지원합니다.

 

이론

각 브라우저에서 지원하는 즐겨찾기 추가 명령을 실행합니다.

이 추가 명령은 브라우저마다 다르므로  분기(IF)처리를 해 주어야 합니다.

 

내용

즐겨찾기추가 스크립트는 다음과 같습니다.

 


function addFavorite() {
    //var title = "Lael's World";   
    //var url = "https://blog.lael.be";
    var title = document.title; //현재 보고 있는 페이지의 Title
    var url = location.href; //현재 보고 있는 페이지의 Url
    if (window.sidebar && window.sidebar.addPanel) { //firefox
        window.sidebar.addPanel(title, url, "");
    } else if (window.opera && window.print) { //opera
        var elem = document.createElement('a');
        elem.setAttribute('href', url);
        elem.setAttribute('title', title);
        elem.setAttribute('rel', 'sidebar');
        elem.click();
    } else if (document.all) { //msie
        window.external.AddFavorite(url, title);
    } else {
        alert("해당브라우저는 즐겨찾기 추가기능이 지원되지 않습니다.\n\n수동으로 즐겨찾기에 추가해주세요.");
        return true;
    }
}

 

 

Leave a Comment

작성하신 댓글은 관리자의 수동 승인 후 게시됩니다.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>
*
*