Jump to content

Trying to get Google Translate script to NOT appear on Https pages


Lisaweb

Recommended Posts

Hi Everyone!  I am new here. I tried to tackle this problem to no avail, so I decided to go to the experts! 

 

I want to call this script by Google in my PHP ecommerce skin:

 

<div id="google_translate_element"></div><script>
function googleTranslateElementInit() {
  new google.translate.TranslateElement({
    pageLanguage: 'en',
    includedLanguages: 'da,nl,fr,de,el,iw,it,ko,ru,es,sv'
  }, 'google_translate_element');
}
</script><script src="http://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>

 

only on pages that are *not* https.  So I am trying to embed the Google code into this directive:

 

<script type="text/javascript">
if (document.location.protocol != "https:")
document.write('...[GOOGLE CODE HERE]...');
</script>

 

This is what I have so far, it looks clean on my editor, but it still isn't working:

 

<script type="text/javascript">
if ( document.location.protocol != "https:" )
        document.write('<div id="google_translate_element"></div>
<script>
function googleTranslateElementInit() {
  new google.translate.TranslateElement({
    pageLanguage: 'en',
    includedLanguages: 'da,nl,fr,de,el,iw,it,ko,ru,es,sv'
  }, 'google_translate_element');
}
</script><script src="https://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
  </div>
');
</script>

 

Any help you experts can provide this newbie would be greatly appreciated!  (Could also try doing this in php, but I don't know how.)

Well ends up someone on another forum answered my question.  Here's the code that fixes the problem for anyone who searches for this problem in the future:

 

<?php
if(!($_SERVER['HTTPS'])) {
?>
<div id="google_translate_element"></div><script>
function googleTranslateElementInit() {
  new google.translate.TranslateElement({
    pageLanguage: 'en',
    includedLanguages: 'da,nl,fr,de,el,iw,it,ko,ru,es,sv'
  }, 'google_translate_element');
}
</script><script src="http://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
<?php
} // End of if statement.
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.