日期:2014-05-16  浏览次数:20296 次

javascript 加入收藏夹 ,适合IE、火狐、chrome、360 ,解决 window.sidebar.addPanel is not a funct

?

/* 加入收藏(适合IE、火狐、chrome、360) */
	function addFavorite2() {
	    var url = window.location;
	    var title = document.title;
	    var ua = navigator.userAgent.toLowerCase();
	    if (ua.indexOf("360se") > -1) {
	        alert("由于360浏览器功能限制,请按 Ctrl+D 手动收藏!");
	    }else if (ua.indexOf("msie 8") > -1) {
	        window.external.AddToFavoritesBar(url, title); //IE8
	    }else if (document.all) {
		  try{
		  	window.external.addFavorite(url, title);
		  }catch(e){
		  	alert('您的浏览器不支持,请按 Ctrl+D 手动收藏!');
		  }
	    } else if (window.sidebar) {
	        window.sidebar.addPanel(title, url, "");
	    } else {
	  		alert('您的浏览器不支持,请按 Ctrl+D 手动收藏!');
	    }
	}

?

<a href="http://xiaoxing598.iteye.com" title="Java-私塾在线学习社区329232140?rel="sidebar" onclick="addFavorite2;">加入收藏</a></div>

?

?

?

如果 <a>上面没有加 “rel=sidebar” ,那么将会报错: window.sidebar.addPanel is not a function