jquery加入收藏代码

<html>
<head>
    <script type="text/javascript" src="jquery-1.9.1.js"></script>

    <script type="text/javascript">
        $(function(){
            var basePath = $("#basePath").val();
            //收藏本站
            $("#favorites").click(function () {        //$里面是链接的id  
                var ctrl = (navigator.userAgent.toLowerCase()).indexOf('mac') != -1 ? 'Command/Cmd' : 'CTRL';  
                if (document.all) {  
                    window.external.addFavorite(basePath, '优一队列');
                } else if (window.sidebar) {  
                    window.sidebar.addPanel('优一队列', basePath, "");
                } else {    //添加收藏的快捷键  
                       alert('添加失败
您可以尝试通过快捷键' + ctrl + ' + D 加入到收藏夹~');
                }
            });
            
            });
    
    </script>  
</head>
<body>

<a href="#" id="favorites">收藏本站</a>

<input type="hidden" name="basePath" id="basePath" value="http://www.youyidl.com" />

</body>
</html>

需要jquery-1.9.1.js的支持~! http://files.cnblogs.com/simpledev/jquery-1.9.1.js

原文地址:https://www.cnblogs.com/simpledev/p/3530877.html