Internet Explorer 8 back button issue with Google +1 button

I’m having trouble with the Google +1 button on my website when using Internet Explorer 8. The problem happens when a user goes to another page and then uses the back button to return. This causes a JavaScript error and the +1 button doesn’t show up.

Here’s the code I’m using for the button:

<div class="social-share">
   <div class="gplus-button"></div>
</div>
<script src="https://apis.google.com/js/platform.js" async defer></script>

The error message I’m seeing is something like:

Message: undefined_variable_123
Line: 3
Char: 21
Code: 0

Has anyone else run into this problem? Any ideas on how to fix it? I’ve tried a few things but nothing seems to work. It’s really frustrating because it’s affecting the user experience on my site.

Thanks for any help you can offer!

I’ve dealt with similar IE8 quirks in the past. One thing that worked for me was adding an event listener for the ‘onbeforeunload’ event. This can help reset the state of dynamic elements like the +1 button when navigating away from the page.

Try adding this JavaScript to your page:

window.onbeforeunload = function() {
if (typeof gapi !== ‘undefined’ && gapi.plusone) {
gapi.plusone.go();
}
};

This forces a refresh of the +1 button before the page unloads, which can help maintain its state when using the back button. Also, make sure you’re using the latest version of the Google+ API script. They’ve made improvements for IE compatibility over time.

If you’re still having issues, you might want to consider using a polyfill for older browsers or implementing a fallback solution for IE8 users. It’s becoming increasingly common to drop support for such outdated browsers in favor of better performance and fewer headaches.

I’ve encountered a similar issue with IE8 and social media buttons. The problem likely stems from IE8’s caching behavior and how it handles JavaScript on page navigation. One workaround I’ve found effective is to use a conditional comment to load a separate script for IE8 users. This script can force a refresh of the +1 button when the page loads.\n\nTry adding this to your HTML:\n\n\n\nThis tells IE8 to re-render the +1 button after the page loads, which should resolve the back button issue. Remember to test thoroughly, as IE8 can be quite finicky with modern web technologies.