0

Any idea why putting google plus code this way wont work in IE8 or any other version I guess? Works just fine in firefox though.

live demo: http://jsfiddle.net/9zqsZ/

<script>

var socialString = '<g:plusone size="tall"></g:plusone>';
document.write(socialString);

   //google plus share button
  (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);
  })();

</script>

I am just trying to put it in external file. The weird thing is it just does not work with document.write and works if is placed directly in html. How to implement it in that case?

1 Answer 1

1

You could do something like:

<script>
    if (navigator.appVersion.indexOf("MSIE") != -1) {
      var socialString = '<g:plusone size="tall"></g:plusone>';
      var newEle = document.createElement(socialString);
      document.body.appendChild(newEle);
    }
    else {
       var socialString = '<g:plusone size="tall"></g:plusone>';
       document.write(socialString);
    }

   //google plus share button
  (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);
  })();
</script>
Sign up to request clarification or add additional context in comments.

5 Comments

My console returns an error putting your code "String contains an invalid character"
thats strange, it worked for me in IE8, may be some extra characters got added while you copied the code, pls check that once
oh, thank you so much. It does work indeed now. So weird the way it acts though. Do you have any explanation why createelement fixes the issue? Just interested to know.
well, i cant be precise on it, but checking this link: social.msdn.microsoft.com/Forums/en-US/iewebdevelopment/thread/… provided me with some hints, hope it helps you too
you could mark it as Accepted answer, if that suited your needs

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.