使用jquery為個人部落格園首頁公告欄添加使用者登入與登出

來源:互聯網
上載者:User

標籤:

  未登入前,登出的字型顏色為黑色,登入後,登入的字型為藍色。

1、在公告欄添加布局顯示代碼
<!--顯示登入 Begin--><!--   隱藏調用html代碼--><div class="hide"><!--------------------------使用者登陸前後顯示------------------------------->    <div class="login_message " style="display: none;"></div>        <div >            <a id="lnkLogin">hi,請登入</a> -             <a href="https://ing.cnblogs.com/" target="_blank">快閃記憶體</a> -             <a href="http://msg.cnblogs.com/inbox" target="_blank">訊息</a> -             <a id="lnkLoginout">登出</a></br>        </div>    </div><!-------------------------使用者登陸前後顯示結束----------------------------></div><!--   隱藏調用html代碼end-->
2、在布局後添加js代碼
<!--******js代碼開始******--><script type="text/javascript">    $(document).ready(function(){        //***************全域變數*************        var dangqurl=window.location.href;  //擷取當前url        var loginy ;   // 登陸狀態        1為已登入         0為未登陸            //ajax擷取設定登入資訊        $.ajax({              url:"http://www.cnblogs.com/GetLoginInfo.aspx",            data:‘{}‘,              type: ‘post‘,            async: false,            dataType: ‘text‘,            contentType: ‘application/json; charset=utf-8‘,            success: function (data){                    if (data) {                        var reset=data.replace(/document\.write\(\"/g,"").replace(/\"\)\;/,"").replace(/\[ /,"").replace(/\]/,"");                     $(".login_message").html(reset);                             loginz=$(".login_message").find("a:first").html();                     bkurl= $(".login_message").find("a:first").attr("href");                 //登入設定                     if(loginz !="登入"){                         $(".headTopRight").html($(".ylogin").html());                          loginy=1  //設定登入狀態                          login_name=loginz;                      //擷取部落格地址                             var bokarr=new Array();                                bokarr=bkurl.split("/");                        bok_link=bokarr[3];                             $(".login_namez").html(loginz);                        $(".login_namez").attr("href","http://www.cnblogs.com/"+bok_link);                        $(".login_namez1").attr("href","http://www.cnblogs.com/"+bok_link);                        $("#lnkLoginout").attr("href","http://passport.cnblogs.com/logout.aspx?ReturnUrl="+dangqurl);                        window.location_href=dangqurl;                        $(".wdyz").attr("href","http://home.cnblogs.com/u/"+bok_link);                          }                    if(loginz=="登入"){                        $(".headTopRight").html($(".nlogin").html());                             loginy=0  //設定登入狀態                                  $("#lnkLogin").attr("href","http://passport.cnblogs.com/login.aspx?ReturnUrl="+dangqurl);                        window.location_href=dangqurl;                    }                //登入 設定結束                }                             },                            erro:function (){                                 loginy=0;                login_type="user";                $(".login_main").html($(".nlogin").html());                $("#lnkLogin").attr("href","http://passport.cnblogs.com/login.aspx?ReturnUrl="+dangqurl);                window.location_href=dangqurl;            }        });        //擷取登入資訊結束    });</script><!--顯示登入 End-->
3、顯示效果

使用jquery為個人部落格園首頁公告欄添加使用者登入與登出

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.