Apr29

设为首页 加入收藏 多浏览器兼容

javascript

找了一圈,发现这个可以用,收藏下来,备用!






<a onclick="SetHome(window.location)" href="javascript:void(0)">设为首页</a>
<a onclick="AddFavorite(window.location,document.title)" href="javascript:void(0)">加入收藏</a>
<script type="text/javascript" language="javascript">
//加入收藏
      function AddFavorite(sURL, sTitle) {
            sURL = encodeURI(sURL);
        try{
            window.external.addFavorite(sURL, sTitle);
         }catch(e) {
            try{
                 window.sidebar.addPanel(sTitle, sURL, "");
             }catch (e) {
                alert("浏览器不支持,请使用快捷键Ctrl+D进行添加!");
             }
         }
     }
</script>
<script type="text/javascript" language="javascript">
 //设为首页
     function SetHome(url){
         if (document.all) {
             document.body.style.behavior='url(#default#homepage)';
                document.body.setHomePage(url);
         }else{
             alert("您好,您的浏览器不支持自动设为首页功能,请您手动在浏览器里设置该页面为首页!");
         }
     }
</script>

Comments are closed.