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.)

Link to comment
Share on other sites

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.
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.