A
A
Andrey Shaydurov2011-07-30 22:52:45
Google
Andrey Shaydurov, 2011-07-30 22:52:45

Google +1 button on loadable content?

Here's how to add a Google +1 button to your site.
However, I've run into trouble where the content it sticks to is loaded via Ajax. In this case, it is shown only once on the first load (and then only if you insert the script tag after the button tag), and nothing after that.
Obviously, when loaded, the script scans the DOM for the necessary tags, turns them into buttons and that's it. Restarting the script doesn't help.
Does anyone have any ideas how to get around this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
Tucker56, 2011-07-31
@GearHead

After generating the content, you need to execute on the page:
gapi.plusone.go();

S
spmbt, 2011-07-31
@spmbt

Yes, of course, you can load the button dynamically. Using the example of a userscript for Habr, you can understand how this is done: spmbt.kodingen.com/habrahabr/habracut06.user.js , and when loading, see how it works on Habré.
function addJs
loadGPlus = function(n)
and this version doesn't add Google's last addition: asynchronous loading (write elemScript.async ='true'; after elemScript.src = url;). But I checked - this parameter really works (when postloading it will not matter).
(Looking at loadGPlus - I would not say that only gapi.plusone.go() should be run there - you need this function, but I don’t remember the details, but it’s clear that .plusone.render() is being launched.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question