Loading Google +1 script dynamically with jQuery.getScript()
-
24-12-2020 - |
Question
i want to load google +1 button only when needed,
<script type="text/javascript" src="https://apis.google.com/js/plusone.js">
{parsetags: 'explicit'}
</script>
so i was thinking of using jQuery.getScript()
to do so like:
$.getScript('https://apis.google.com/js/plusone.js', function(data, textStatus){});
or
$.ajax({
url: url,
dataType: "script",
success: success
});
but how can i pass the parsetags: 'explicit'
param ?
Solution
Well, dont bother, i found a solution:
$.ajax({
url: "https://apis.google.com/js/plusone.js",
dataType: "script",
parameters: { parsetags: "explicit" },
success: function () { gapi.plusone.go(); }
});
OTHER TIPS
Set a global variable as follows, then load the g+ script:
window['___gcfg'] = { parsetags: 'explicit' };
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow