[JavaScript]跨浏览器的加入书签

 1function addBookmark() {
 2    var links = document.getElementsByTagName('a');
 3    if(!links) return;
 4    for(var i=0; i<links.length; i++{
 5        if(links[i].getAttribute('rel'== 'bookmark'{
 6
 7            var p_title = document.title;
 8            var p_url = window.location.href;
 9            if (document.all && !window.opera){
10                links[i].setAttribute('href'"javascript:window.external.AddFavorite('" + p_url + "', '" + p_title + "')");
11            }

12            else if ((typeof window.sidebar == 'object'&& (typeof window.sidebar.addPanel == 'function')){
13                links[i].setAttribute('href'"javascript:window.sidebar.addPanel ('" + p_title + "', '" + p_url + "','')");
14            }

15            else {
16                links[i].href = "" + p_url + "";
17            }

18        }

19    }

20}
利用rel属性,将其值设置为bookmark即可为a元素添加此功能。
参考来源:
http://home.arcor.de/xbo/sidebar-cross-browser/
posted on 2008-06-20 12:52  豆豆の爸爸  阅读(1050)  评论(0编辑  收藏  举报