现在的位置: 首页 > 综合 > 正文

jQuery 添加收藏夹+设为首页+回到顶部

2013年08月27日 ⁄ 综合 ⁄ 共 778字 ⁄ 字号 评论关闭

//添加到收藏夹
 $(".favorites").click(function (){
     var ctrl = (navigator.userAgent.toLowerCase()).indexOf('mac') != -1 ? 'Command/Cmd' : 'CTRL'; 
     if (document.all)
     {  
      window.external.addFavorite(window.location, document.title);
     }
     else if (window.sidebar)
     { 
      window.sidebar.addPanel(document.title,window.location); 

     }
     else
     {//添加收藏的快捷键 

      alert('添加失败\n您可以尝试通过快捷键' + ctrl + ' + D 加入到收藏夹~'); 
     } 
 }) ;

 

//设置主页
 $("#addHomePage").click(function () {
     if (document.all) {//设置IE 
  document.body.style.behavior = 'url(#default#homepage)';
  document.body.setHomePage(document.URL); 

     }
     else
     {//网上可以找到设置火狐主页的代码,但是点击取消的话会有Bug,因此建议手动设置 
      alert("设置首页失败,请手动设置!"); 
     } 
 });

 

//回到顶部
 $("#backToTop").click(function(){$('body,html').animate({scrollTop:0},1000);return false;});

 

抱歉!评论已关闭.