472084
472084

Reputation: 17895

Changing the href on gplus & facebook buttons using javascript

My website is [link-removed] and when you change the page from the main menu it uses ajax to load the main content div, this means the social buttons on the right are still pointing to the original page you landed on, how can I update them along with the page content?

I have tried

$('.sidebar g\\:like').attr("href", x);
$('.sidebar fb\\:like').attr("href", x);

But doesn't seem to work

Any ideas? I am surprised I couldn't find a somebody with a similar problem...

Upvotes: 0

Views: 438

Answers (2)

hunter
hunter

Reputation: 63522

It would be easier to dump than iframe and re-add it for the facebook like portion:

$('#social fb').remove(); //fb seems to create a fb:like element... wierd

$('#social').append(
    '<iframe src="http://www.facebook.com/plugins/like.php?href="' + url + '"
    scrolling="no" frameborder="0" 
    style="border:none; width:450px; height:80px"></iframe>');

and do the same with the G+

$('#social [id*=plusone]').remove();

Upvotes: 0

wesbos
wesbos

Reputation: 26317

Both of those buttons are iFrames, so you wont be able to do that unless you use the facebook JS API for facebook. I dont think g+ has a non-iframe solution..

You would need to swap the entire button out with something like:

$('#social').html('<iframes to facebook and g+ buttons />');

Upvotes: 1

Related Questions