Google+ plusone button (+1) on mobile devices

How to enable the +1 button on mobile devices like iPhone, iPad and Android. Here's the fix!

Google+ is the new thing that is like facebook, but not facebook. Now site owners can put up +1-buttons on their pages which is pretty much the same as facebook "like" buttons, but for Google+. They look like this (press it and you'll +1 carloscar.se)

However, these plusone-buttons doesn't show up on mobile devices, like iPad, iPhone or Android unless you load a different JavaScript when going mobile. I'm posting this just because I had a hard time myself finding a somewhat nice solution to all of this.

Start off with removing the line <script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script> entirely from your project and instead paste the following code on the very bottom of your <body> element:

<script> (function () { var s = document.createElement('script'); s.async = true; s.type = 'text/javascript'; s.src = 'https://apis.google.com/js/plusone.js'; if (typeof(navigator) != 'undefined' && navigator.userAgent && /iPad|iPhone|Android/.test(navigator.userAgent)) s.src = "https://ssl.gstatic.com/webclient/js/gc/" + "22224365-adc8a19e" + // changed whenever Google make changes "/googleapis.client__plusone.js"; (document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s); }()); </script>
And that's it. Now the +1 button will show up on your iPad, iPhone or Android device too. But please note that the string "22224365-adc8a19e" should be changed whenever Google makes any changes to their plusone-button-code, the old version will still be available since they're not removing anything but it could be good to keep up to date, until they actually enable use of the +1 button for all platforms.

In case you were wondering, since I'm a web developer, I'm sneaking in this little post about something else than photography and that's why I'm writing about this weird stuff. Well, here's an old photo so it's not totally out of context. :)



If you're missing a Google+ account and want to try it out, give me a shout and I'll throw an invite your way. A cool community-like service isn't as cool without the users you care about.

Carl Oscar Aaro
Carl Oscar Aaro
,
00:46 the 4th of July, 2011