Detect Browser Language and Redirect

$( document ).ready(function(){
    var userLang = navigator.language || navigator.userLanguage;
    if (userLang == "en") {
        break;
    }
    else if(userLang == "es"){
       window.location.href = "www.facebook.com"
    }
    else if(userLang == "ca"){
       window.location.href = "www.youtube.com"
    }
    else {
        window.location.href = "www.google.com"
    }
});

This should work.
PLEASE NOTE - its showing inconsistent quotations around es and ca. Dont copy and paste this. I dont know why the forums aren’t showing the correct single or double quotation…

Moderator edit: @steelesong I took the liberty to edit your message to fix the quotes.Thank you for posting solutions on the forum.

1 Like