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?
To customized the button:
Head Part:
Body Part: In my case I am using php I set the body attributes like this.
To update content dynamically (JS Part):
It is as simple as this:
Cheers, Gary
I used a global variable
shareConfig
to keep track of the URL and title configuration. I have multiple addthis buttons in a webpage, each sharing different content. Therefore I have added aisSameNode
to make sure I only update the button I want.Although URL and title are changed dynamically, the
addthis:url
andaddthis:title
attributes must be present in the button (<span>
), or else it won't work.AddThis provides addthis.update("share", "url", value) function (but it is a buggy function in IE8); try this one:
Step-1: Preparing ajax content to be loaded with other HTML;
Step-2: Preparing my fancybox ajax setup;
The above lines inside the "afterShow()" function are important to keep a note;
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:http://www.sourcen.com ---> new url