How can I get the state ("on" or "off") of the Google +1 button?
Asked Answered
T

1

10

The +1 API documentation is here: http://code.google.com/apis/+1button/#jsapi

There is no mention of how to determine whether the viewing user has already clicked the button or not. This would be a very useful function because it would allow me to encourage people who haven't +1'd a page to do so without putting users who have already +1'd the page through a needless and possibly confusing step.

Has anyone found a way to do this? Thanks

Threlkeld answered 7/6, 2011 at 17:40 Comment(5)
(Unrelated comment about an answer edit elsewhere: you do have the reputation to answer questions, and your edit would have made a fine enough answer had it stood on its own. :)Mariehamn
Incidentally, I'd be annoyed if a website begged me to click a magical +1 button for them from a service I care nothing about.Mariehamn
I was thinking of reading the aria-pressed attribute (on the button link itself) whether it says true or false (on or off), but Google wraps the button in an iframe, and using jQuery to get the iframe's content throws a Unsafe JavaScript attempt to access frame with URL error in Chrome (of course, it's cross-domain). I hope someone has an answer to thisDx
No, I don't think there's any way to do it.Chromoplast
Ever find the answer ? I'd like to detect the state onload.Clachan
P
1

There is callback attribute, which allows you to add custom callback function, which can react to +1 or -1. See http://www.odditysoftware.com/blog/trap-and-track-google-plus-button-click-events_45.html

But your question is old, maybe it wasn't present yet.

Pastime answered 28/10, 2011 at 8:14 Comment(1)
I wanted to get the state of the button BEFORE it was clicked. The issue is that people often don't know if the button is on or off, so they get confused and UN-+1 something they intended to +1Threlkeld

© 2022 - 2024 — McMap. All rights reserved.