JS兼容所有浏览器的一段加入收藏代码,设置为首页

时间:2022-04-23
本文章向大家介绍JS兼容所有浏览器的一段加入收藏代码,设置为首页,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
<script language="javascript" type="text/javascript">
 function addfavorite(obj,url,title) { 
  !url ? url = location.href : null;
  !title ? title = document.title : null;
  try{   
   window.external.addFavorite(url, title); 
   return false;
  }catch(e){   
   try{   
    window.sidebar.addPanel(title, url, ""); 
    return false;  
   }catch(e){   
    alert("加入收藏失败,请使用Ctrl+D进行添加"); 
    if(location.href.toLowerCase().indexOf(obj.href.toLowerCase(),0)>=0){return false;} 
   }   
  }   
 }
</script>
<a href="http://dreamdesign.csrjgzs.com/" onclick="return addfavorite(this,'http://dreamdesign.csrjgzs.com/','阿里西西,最多最全的网页特效集锦!');">收藏阿里西西!</a>
设置为首页 

var strHref=window.location.href;this.style.behavior='url(#default#homepage)'; this.setHomePage('http://www.dotneteye.com.cn');