Skip to content

Instantly share code, notes, and snippets.

@sadjow
Created April 1, 2013 15:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sadjow/5285546 to your computer and use it in GitHub Desktop.
Save sadjow/5285546 to your computer and use it in GitHub Desktop.
Dynamic load addthis tag after ajax calls
$(document).ajaxStop(function() {
if (window.addthis) {
window.addthis = null;
window._adr = null;
window._atc = null;
window._atd = null;
window._ate = null;
window._atr = null;
window._atw = null;
}
return $.getScript("http://s7.addthis.com/js/300/addthis_widget.js#pubid=sdive");
});
@crmpicco
Copy link

Does this work when there are more than one instances of AddThis on the page?

@RomanStone
Copy link

addthis.layers.refresh();
https://www.addthis.com/academy/using-dashboard-configuration-tools-dynamically/

(function(a, b, x) {
    var s = document.createElement("script");
    s.onload = function() {
        setTimeout(function() {
            if (typeof(jQuery) !== "undefined") {
                jQuery(document).ajaxStop(function() {
                    if (typeof(window.addthis) === "object" && typeof(window.addthis.layers) === "function" && typeof(window.addthis.layers.refresh) === "function") {
                        window.addthis.layers.refresh();
                    }
                })
            }
        }, 300)
    };
    s.src = "//s7.addthis.com/js/300/addthis_widget.js#pubid=0000000000000000";
    document.getElementsByTagName("head")[0].appendChild(s);
})(document, "script", undefined);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment