首页 > 代码库 > JS积累

JS积累

1. <a>标签"加入收藏",兼容IE,FireFox等

function bookmarksite() {            if (window.sidebar) {                 // Mozilla Firefox Bookmark                window.sidebar.addPanel(document.title, window.location.href, ‘‘);            }            else if (window.external && (‘AddFavorite‘ in window.external)) {                 // IE Favorite                window.external.AddFavorite(location.href, document.title);            } else if (window.opera && window.print) {                 // Opera Hotlist                this.title = document.title;                return true;            } else {                 // webkit - safari/chrome                alert(‘Press ‘ + (navigator.userAgent.toLowerCase().indexOf(‘mac‘) != -1 ? ‘Command/Cmd‘ : ‘CTRL‘) + ‘ + D to bookmark this page.‘);            }        }        //加入收藏        function bookmarksite(title, url) {            if (window.sidebar) // 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)// ie                        window.external.AddFavorite(url, title);            }
View Code

 

JS积累