Search code examples
javascriptjqueryinternet-explorergoogle-plus-one

Changing innerHTML of script tags in IE for loading google plusone button explicitly


To add Google's plusone button on your website the following script tag is to be inserted (for explicit load).

<script type="text/javascript" src="https://apis.google.com/js/plusone.js">
  {"parsetags": "explicit"}
</script>

It looks pretty straight forward in HTML. However I wan't to insert the script using a JS file. So I use the following code:

var e = document.createElement('script');
e.src = "https://apis.google.com/js/plusone.js";
e.id = "googplusonescript";
e.innerHTML = '{"parsetags": "explicit"}';
document.getElementsByTagName("head")[0].appendChild(e);

It works pretty awesome in all the browsers except IE because IE doesn't allow us to write the innerHTML of script tags. Anywork arounds anyone ? (I have jquery inserted in the page. So can use jquery too.)


Solution

  • Came across the same issue. Under IE you should use script.text = '{"parsetags": "explicit"}'; instead of script.innerHTML