AddThis button will not work inside AJAX, but will work normally

后端 未结 8 860
温柔的废话
温柔的废话 2021-02-04 17:47

Basically, this is what I\'m doing. User visits site, loads \"index.html\" Within index.html, it automatically loads, through AJAX, \"details.html\" into a DIV. I put an ADDTHIS

8条回答
  •  Happy的楠姐
    2021-02-04 18:02

    I recently ran in to issues with using AddThis on an all AJAX site and was able to come up with a couple of solutions for this issue.

    It turns out there is a variable that you can pass when loading the AJAX script as well as a way to re-initialize the script if the DOM is reloaded via AJAX. I have posted the full solution in detail on my blog here:

    http://joecurlee.com/2010/01/21/how-to-use-addthis-with-ajax-and-overflowauto/

    To briefly summarize, the solution is loading AddThis with the variable domready=1 appended, and re-initializing the script by deleting the initial load and then reloading the script dynamically:

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

提交回复
热议问题