码迷,mamicode.com
首页 > Web开发 > 详细

JS积累

时间:2014-09-22 10:25:32      阅读:294      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   os   ar   div   sp   

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

bubuko.com,布布扣
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积累

标签:style   blog   http   color   io   os   ar   div   sp   

原文地址:http://www.cnblogs.com/xinaixia/p/3985373.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!