js get current language code example

Example 1: jquery get current url

var currentURL = $(location).attr('href'); //jQuery solution
var currentURL = window.location.href; // raw javascript

Example 2: javascript get user preferred language

//detect the language preference of the user's browser
var userLanguage = window.navigator.userLanguage || window.navigator.language;

Example 3: react chrome get language

<script type="text/javascript">
var userLang = navigator.language || navigator.userLanguage; 
alert ("The language is: " + userLang);
</script>

Example 4: check browser locale javascript

check locale using js