Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change AddThis url dynamically with jQuery

Tags:

jquery

addthis

I am trying to dynamically change the URL sent by addthis. When a user alters an element it updates a text area containing a custom url so they can return to that url and continue/view their work.

I am creating an addthis button like so(from their API docs):

var addthis_share = {url:"http://www.johndoe.com"}
$(document).ready(function(){
    var tbx = document.getElementById("toolbox"),
    svcs = {email: 'Email', print: 'Print', facebook: 'Facebook', expanded: 'More'};
    for (var s in svcs) {
        tbx.innerHTML += '<a class="addthis_button_'+s+'">'+svcs[s]+'</a>';
    }
    addthis.toolbox("#toolbox");
});

Then when the url is updated I am trying to update the addthis share URL like so:

function updateURL(){
    ...get some variables here and generate a new url
    var newURL="http://the.url.i.want.to.share.com";
    $('#tagUrl').val(newURL);
    //addthis_share = {url:newURL}
    addthis_share = {url:newURL}
    addthis.toolbox("#toolbox");
} 

The original buttons are getting generated and contain the correct url, but when the url update function executes the addthis share url is not getting updated. How can I force it to update the addthis url?

like image 542
maddogandnoriko Avatar asked Mar 12 '13 16:03

maddogandnoriko


1 Answers

If you wants to change the addthis url after the html is loaded (in case of ajax or some user events),  please use the below hack . Addthis apis are broken as on [09/04/13 11:42:24 AM] sunny jhunjhunwala:

addthis.update('share', 'url', 'http://www.sourcen.com'); 
addthis.url = "http://www.sourcen.com";                
addthis.toolbox(".addthis_toolbox");

http://www.sourcen.com ---> new url

like image 92
sunnyuff Avatar answered Oct 13 '22 12:10

sunnyuff