Google translate element - load after page ready

前端 未结 2 490
春和景丽
春和景丽 2021-01-17 03:14

I am using the google web translate element on my page. For those that don\'t know what it is you can find it here: http://translate.google.com/translate_tools

It lo

相关标签:
2条回答
  • 2021-01-17 03:29

    Another method would be to load google translate asynchronously.

    <div class="custom-translate" id="google_translate_element"></div>
    
    <!-- ASYNCHRONOUS Google Translate -->
            <script type="text/javascript">
            function googleTranslateElementInit() {
              new google.translate.TranslateElement({pageLanguage: 'en', layout: google.translate.TranslateElement.InlineLayout.SIMPLE, autoDisplay: false},'google_translate_element');
            }
    
            (function() {
              var googleTranslateScript = document.createElement('script');
              googleTranslateScript.type = 'text/javascript';
              googleTranslateScript.async = true;
              googleTranslateScript.src = '//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit';
              ( document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0] ).appendChild( googleTranslateScript );
            })();
            </script>   
        <!-- End script -->
    
    0 讨论(0)
  • 2021-01-17 03:35

    As commented by John Conde, I put the script at the bottom of the page and hey presto, page load

    0 讨论(0)
提交回复
热议问题