Are there any ways to add google button plus +1 js dynamically? I need this because there are many URLs on the page and they got AJAX. Therefore, when I get the right URL, I want to generate "+1" -s in some places on the page.
I wrote test code that works in all browsers except IE8 (IE7 is not supported by Google at all):
<div class="googlePlusBtn"></div> <a href="#" class="addGooglePlus">Click me!</a>
<script type="text/javascript"> jQuery(function(){ jQuery('.googlePlusBtn').html('<g:plusone annotation="inline"></g:plusone>'); jQuery('a.addGooglePlus').click(function() { var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true; po.src = 'https://apis.google.com/js/plusone.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s); return false; }) }) </script>
Could you help me?
UPD: Fixed. The solution is below:
<div id="googlePlusBtn"></div> <a href="#" class="addGooglePlus">Click me!</a>
<script type="text/javascript"> jQuery(function(){ var po = document.createElement('g:plusone'); var s = document.getElementById('googlePlusBtn'); s.appendChild(po); jQuery('a.addGooglePlus').click(function() { var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true; po.src = 'https://apis.google.com/js/plusone.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s); return false; }) }) </script>
So, just changed the method of creating a document from jQuery to clear Javascript. IE8 works with this!
Eugene kuzmin
source share