首页

源码搜藏网

首页 > 开发教程 > IT博文 > Web前端 > jQuery技术 >

JQUERY 加入收藏夹、设为首页代码

创建时间:2013-05-13 14:02  

<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script> 
02  
03 //添加到收藏夹 
04 <script type="text/javascript"
05  
06     $(document).ready(function () { 
07  
08     $("#favorites").click(function () { //$里面是链接的id 
09  
10         var ctrl = (navigator.userAgent.toLowerCase()).indexOf('mac') != -1 ? 'Command/Cmd' 'CTRL'
11  
12         if (document.all) { 
13  
14         window.external.addFavorite('http://www.baidu.com''百度'
15  
16         else if (window.sidebar) { 
17  
18         window.sidebar.addPanel('百度''http://www.baidu.com'""
19  
20         else { //添加收藏的快捷键 
21  
22         alert('添加失败\n您可以尝试通过快捷键' + ctrl + ' + D 加入到收藏夹~'
23  
24         
25  
26     }) 
27  
28     }); 
29  
30 </script> 
31  
32  
33 //设置主页 
34  
35 $("#addHomePage").click(function () { 
36  
37         if (document.all) {//设置IE 
38  
39         document.body.style.behavior = 'url(#default#homepage)'
40  
41         document.body.setHomePage(document.URL); 
42  
43         else {//网上可以找到设置火狐主页的代码,但是点击取消的话会有Bug,因此建议手动设置 
44         alert("设置首页失败,请手动设置!"); 
45         
46 })
上一篇:Jquery Ajax异步处理Json数据.详谈
下一篇:CSS和jQuery的五个实用技巧

相关内容

热门推荐