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

跟風遠走 提交于 2019-12-04 14:02:02

问题


Let's say I have a webpage and I have added the 1+ button.

Is there a good way to tell if the user has already pressed the 1+ button on a previous visit.

I'd like to present a thank you on all the viewers visit if they've 1+ the page.


回答1:


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");
  }
}


来源:https://stackoverflow.com/questions/6575274/is-there-a-easy-way-to-tell-if-a-user-has-google-1-a-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!