最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Detect if a web user is currently logged in Google? - Stack Overflow

programmeradmin4浏览0评论

Suppose I want to display certain content only if I know the user coming to my website has a valid Google Account and it's logged into that account.

Is there any way to do this in Javascript? I know that the Facebook API provides ways to tell the status of a user (logged in Facebook) and I'm sure I've seen sites doing this with Google Accounts as well, but searching for the relevant terms in Google leads me to nowhere as the search terms are poorly focused.

Thank you for any help.

Suppose I want to display certain content only if I know the user coming to my website has a valid Google Account and it's logged into that account.

Is there any way to do this in Javascript? I know that the Facebook API provides ways to tell the status of a user (logged in Facebook) and I'm sure I've seen sites doing this with Google Accounts as well, but searching for the relevant terms in Google leads me to nowhere as the search terms are poorly focused.

Thank you for any help.

Share Improve this question asked Nov 17, 2010 at 8:47 Cristiano ParisCristiano Paris 1,8562 gold badges15 silver badges21 bronze badges 1
  • Because I want to display links only if a user is logger to Google. – Cristiano Paris Commented Feb 9, 2011 at 13:40
Add a comment  | 

2 Answers 2

Reset to default 11

This blog claims to have done it, via checking for image return values linked to the social platforms provided by G+ / twitter / etc

http://www.tomanthony.co.uk/blog/detect-visitor-social-networks/

<img style="display:none;"
onload="show_login_status('Google', true)"
onerror="show_login_status('Google', false)"
src="https://accounts.google.com/CheckCookie?continue=https%3A%2F%2Fwww.google.com%2Fintl%2Fen%2Fimages%2Flogos%2Faccounts_logo.png&followup=https%3A%2F%2Fwww.google.com%2Fintl%2Fen%2Fimages%2Flogos%2Faccounts_logo.png&chtml=LoginDoneHtml&checkedDomains=youtube&checkConnection=youtube%3A291%3A1"
/>
<script type="text/javascript">
function show_login_status(network, status){

    if(status == false){
        alert('NOT LOGGED IN');
    }
    if(status == true){
        alert('Logged In');
    }


}


</script>

<img style="display:none;"
onload="show_login_status('Google', true)"
onerror="show_login_status('Google', false)"
src="https://accounts.google.com/CheckCookie?continue=https%3A%2F%2Fwww.google.com%2Fintl%2Fen%2Fimages%2Flogos%2Faccounts_logo.png&followup=https%3A%2F%2Fwww.google.com%2Fintl%2Fen%2Fimages%2Flogos%2Faccounts_logo.png&chtml=LoginDoneHtml&checkedDomains=youtube&checkConnection=youtube%3A291%3A1"
/>

This will work.

发布评论

评论列表(0)

  1. 暂无评论