Reputation: 7800
I have a link that a user can share on fb
and G+
.
The user can modify that link and he did it with an ajax call so the page is not refreshing.
My gplus button code :
<link rel="canonical" href="{{ url }}" />
<g:plus action="share" style="height: 28px;" ></g:plus>
when the user changes the url I update the href
attribute too :
$.post(url,{
someParams:"someValues"
},function(data){
.
.
.
// updating the href attribute with the new modified url
$('link[rel="canonical"]').attr("href",data.url);
}
The problem is that the G+
button still load the old url.
But only by refreshing I get the new one.
My question is how can i change the G+
url without refreshing the page ?
Upvotes: 1
Views: 254
Reputation: 16649
Is this what you want (obviously changing that prompt for your ajax callback logic)?
http://jsfiddle.net/coma/2783J/6/
HTML
<!-- Place this tag where you want the +1 button to render. -->
<div id="gplus"></div>
<button>change it!</button>
JS
$(function() {
var container = $('#gplus');
var render = function(url) {
container.html('<g:plusone href="' + url + '"></g:plusone>');
gapi.plusone.go('gplus');
};
$('button').click(function(event){
var url = prompt('Give me an URL');
render(url);
});
render(location.href);
});
Be aware that I'm loading the plusone.js in the external resources of that jsfiddle.
BTW, why did you use the Symfony2 tag?
Upvotes: 1