The task is to write a script in javaScript/jQuery(other technologies also possible) to return the domain with a .pl extension if the user language browser is set to Polish. Otherwise, the script should return .eu domain extension
I tried to use jQuery, but I cannot find an appropriate solution.
<script type="text/javascript">
$(document).ready(function () {
var userLang = navigator.language || navigator.userLanguage;
var path = window.location.path;
var extension = window.location.hostname;
var ext = extension.split(".");
var x = ext[2];
if (userLang.startsWith("pl")) {
x = "pl";
window.location.href = extension + x + path;
else {
x = "eu"
window.location.href = extension + x + path;
}
});
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
I expect www.domain.pl/file1/files2/file3.html(it is possible to have many directories by the link) if navigator.language = "pl" else href = www.domain.eu/path
Thank you in advance for any contributions.