I'm trying to send visitors that have browser language in English to an alternative site. I was able to find this code but it's not working:
<script type="type/javascript">
var language = navigator.browserLanguage;
// alert(language);
if (language.indexOf('en') > -1) {
document.location.href = 'http://en.socialpos.com.ar';
} else {
document.location.href = 'http://socialpos.com.ar';
}
</script>
I'm not even getting the alert :/
You can see it in http://socialpos.com.ar
Click the URL Redirects tab. In the upper right, click Add URL redirect. In the right panel, select the Standard or Flexible redirect type. A standard redirect is used to redirect one URL to another.
A JavaScript redirect is a piece of JavaScript code that is used to automatically transfer a visitor from a landing page to a different target page.
Does Google crawl and index redirects? No, it does not. This means that if you redirect from one page to another, the content on the original page will not get indexed. Only the target URL will be crawled and indexed by the search engine.
To enable browser language redirect, go to WPML → Languages page, and find the Browser language redirect. The default is to not redirect visitors. If you choose to redirect visitors, you can have two options: Only redirect visitors if translations exist.
var language = navigator.browserLanguage;
should be
var language = navigator.language || navigator.browserLanguage; //for IE
see my console results:
var language = navigator.browserLanguage;
undefined
language;
undefined
var language = navigator.language;
undefined
language;
"en-US"
Also please note that this was the first result for a google search: "javascript browser language". Google is your friend, and your google-fu is weak. Train it with searches!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With