Is there a easy way to tell if a user has google 1+ a URL

喜夏-厌秋 提交于 2019-12-03 08:05:32

In the +1 API there is a callback method which you can use to trap +1's

A strategy would be to trap these calls and store a cookie on the browser. Next time the user comes, you can check the cookie and show the thanks message.

From the docs

callback The identifier for a function in the global namespace

Called after the user has clicked the +1 button. The callback function may accept a JSON object which will be of the form, {"href": "http://www.example.com/", "state": "on"}. Where href is the URL of the +1 and state is on for a +1 and off for the removal of a +1.

A quick example:

function plus1Callback(params)
{
  if(params.state == "on"){
    setCookie("hasplus1", "true");
  }
}

function checkHasPlus1()
{
  var hasplus1=getCookie("hasplus1");

  if (hasplus1!=null && hasplus1!=""){
    alert("Thanks for your +1");
  }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!