javascript - Google Translate isn't Hidden -


having opted "automatic" version of google translate widget, expected not see "select language" dropdown if browser same language site. however, see time no matter set html lang attribute or set browsers preferred language to. have noticed doesn't seem make difference whether meta "google-translate-customization" tag there or not, widget in view.

i'd site translated if users browser isn't set english.

any advice appreciated.

code used:-

in head:-

<meta name="google-translate-customization" content="6bb255d109276506-b73cb06230e6b6c0-gbb2acb9bc95b4a11-12"></meta> 

in body:-

   <div id="google_translate_element"></div>             <script>             function googletranslateelementinit() {               new google.translate.translateelement({pagelanguage: 'en', layout: google.translate.translateelement.floatposition.top_left}, 'google_translate_element');             }             </script>             <script src="//translate.google.com/translate_a/element.js?cb=googletranslateelementinit"></script> 

you can try small jquery script:

var userlang = navigator.language || navigator.userlanguage;  if(userlang == "en"){     $("#google_translate_element").css(["display", "none"]); } 

not sure if if right i'm using dutch browser , showed nl userlang. i'm pretty sure english 1 should named en. otherwise have alert userlang , change that.

alert(userlang); 

heres jsfiddle: http://jsfiddle.net/u950mwom/1/


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -