I have implemented the Pinterest image hover widget on my website to allow users to easily pin images to their Pinterest accounts.
You can find the widget here. (Make sure to click the image hover radio button under button type to see the one I am using.)
While the Pinterest button works perfectly on other pages without AJAX content loading, I am facing an issue when trying to load content in a popup window via AJAX and include the Pinterest button with that content. I have attempted to delay loading the Pinterest code until after the AJAX request is complete, but have not had success so far. I have tried the following approach:
<script type="text/javascript">
jQuery(document).ajaxComplete(function() {
(function(d){
var f = d.getElementsByTagName('SCRIPT')[0], p = d.createElement('SCRIPT');
p.type = 'text/javascript';
p.setAttribute('data-pin-hover', true);
p.async = true;
p.src = '//assets.pinterest.com/js/pinit.js';
f.parentNode.insertBefore(p, f);
}(document));
});
</script>
I have made sure that the Pinterest code is only loaded on this page using the method above after the AJAX request has inserted the additional content into the DOM. Despite trying various other methods found online, none of them have provided a solution. If anyone has successfully integrated the image hover widget with AJAX before, any advice would be greatly appreciated.
Thank you :)