woutr_be
woutr_be

Reputation: 9722

AddThis & AJAX loading doesn't change title and URL

I'm currently working on a website where the content is loaded via AJAX, every piece of content has some AddThis sharing buttons.

So after the content is loaded and added into a div container, I reload the AddThis script in order to make it work again:

var script = 'http://s7.addthis.com/js/250/addthis_widget.js#pubid=myid&domready=1';
if(window.addthis) window.addthis = null;
$.getScript( script );

But when I share the page, I noticed that the title and url don't change, I did change the title manually:

var title = $(response).find('h2').text();
window.document.title = title;
window.history.pushState({path: href}, title, href);

Why won't AddThis use this new title and URL? Also for the Facebook sharing it's using the image from the first content. (probably because of the wrong url)

Upvotes: 2

Views: 4772

Answers (2)

ronnyfm
ronnyfm

Reputation: 2081

You could try this too (I found a bug in IE8, becauses AddThis uses for..in:

for(var i = 0; i < addthis.links.length; i++){
    addthis.links[i].share.url = "new url";
    addthis.links[i].share.title = "new title";
}

Upvotes: 0

woutr_be
woutr_be

Reputation: 9722

Apparently I forgot to call addthis.update(), this fixed my problem.

AddThis buttons wont update to include fragment (#Hash Tag)

Upvotes: 2

Related Questions