您的位置:首页 > 其它

'加入收藏' 功能

2016-01-29 19:36 399 查看
第一种写法:例子

<a href="javascript:void(0);" target="_self" onclick="javascript:try{ window.external.AddFavorite('http://www.butao.com','步淘'); } catch(e){ (window.sidebar)?window.sidebar.addPanel('360安全网址','http://hao.360.cn/',''):alert('请使用按键 Ctrl+d,收藏360安全网址'); }">加入收藏</a>


第二种写法:例子

<a href="#" onclick="addfavorite()">加入收藏!</a>

<script>
function addfavorite(){

if (document.all){
window.external.addFavorite('http://www.baidu.com','收藏夹');

} else if (window.sidebar){
window.sidebar.addPanel('百度一下', 'http://www.baidu.com', "");

} else {
alert( "请使用 Ctrl+D 进行添加" );
}

}
</script>


第三种写法:例子

<a href="javascript:;" onclick="AddFavorite('http://www.butao.com','butao')">把www.butao.com加入收藏</a>

<script>
function AddFavorite(sURL, sTitle){
try{
window.external.addFavorite(sURL, sTitle);
} catch (e){
try{
window.sidebar.addPanel(sTitle, sURL, "");
} catch (e){
alert("加入收藏失败,请使用Ctrl+D进行添加");
}
}
}
</script>


第四种写法:例子

<a href="javascript:;" onclick="javascript:addfavor(' http://www.butao.com','butao');">加入收藏</a> 
<script language="javascript">
function addfavor(url,title) {
if(confirm("网站名称:"+title+"n网址:"+url+"n确定添加收藏?")){
var ua = navigator.userAgent.toLowerCase();
if(ua.indexOf("msie 8")>-1){
external.AddToFavoritesBar(url,title,'butao');  //IE8
}else{
try {
window.external.addFavorite(url, title);
} catch(e) {
try {
window.sidebar.addPanel(title, url, "");  //firefox
} catch(e) {
alert("加入收藏失败,请使用Ctrl+D进行添加");
}
}
}
}
return false;
}
</script>


第五种写法:例子

<a href="javascript:void();" onclick="addfavorite()">将本页加入收藏</a>

<script language="javascript">
var isIE =(document.all&&document.getElementByIdx_x_x_x_x_xx_x&&!window.opera)?true:false;
var isMozilla=(!document.all&&document.getElementByIdx_x_x_x_x_xx_x&&!window.opera)?true:false;

var weburl=window.location.href;
var webname=document.title;

function addfavorite(){
if(isMozilla){
if (document.all){
window.external.addFavorite(weburl,webname);
}else if(window.sidebar){
window.sidebar.addPanel(webname,weburl,"");
}
} if(isIE){
window.external.AddFavorite(weburl, webname);
}
}
</script>


第六种写法:使用图片实现加入收藏的效果:

<a onClick="this.style.behavior='url(#default#homepage)';this.setHomePage('http://www.baidu.com');" href="javascript:;" title="设为首页"><img src="Images/about_2.gif" border="0" width="84" height="19" title="设为首页" /></a>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: