Note that there are some explanatory texts on larger screens.

plurals
  1. POAdd Google plus +1 button dynamically and IE8 problem
    primarykey
    data
    text
    <p>Are there any ways to add Google plus +1 button by js dynamically? I need that because a page has many URL's to share and they gotten by AJAX. So, when I get needed URL's I want to generate "+1"-s in some places of the page.</p> <p>I have written test code which works in all browsers except IE8 (IE7 is not supported by Google at all):</p> <pre class="lang-html prettyprint-override"><code>&lt;div class="googlePlusBtn"&gt;&lt;/div&gt; &lt;a href="#" class="addGooglePlus"&gt;Click me!&lt;/a&gt; </code></pre> <pre class="lang-js prettyprint-override"><code>&lt;script type="text/javascript"&gt; jQuery(function(){ jQuery('.googlePlusBtn').html('&lt;g:plusone annotation="inline"&gt;&lt;/g:plusone&gt;'); 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; }) }) &lt;/script&gt; </code></pre> <p>Could you please help me?</p> <p><strong>UPD:</strong> Fixed. The solution is below:</p> <pre class="lang-html prettyprint-override"><code>&lt;div id="googlePlusBtn"&gt;&lt;/div&gt; &lt;a href="#" class="addGooglePlus"&gt;Click me!&lt;/a&gt; </code></pre> <pre class="lang-js prettyprint-override"><code>&lt;script type="text/javascript"&gt; 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; }) }) &lt;/script&gt; </code></pre> <p>So, just changed create document method from jQuery to clean Javascript. IE8 works with that!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload