Solution:1
You can get the path from JavaScript’s built-in Location, window.location.pathname.split('/')[1]
will give you the first segment of the path, depending on your url this will be either “fr”, “de” or “en”
Solution:1
You can get the path from JavaScript’s built-in Location, window.location.pathname.split('/')[1]
will give you the first segment of the path, depending on your url this will be either “fr”, “de” or “en”
Solution:2
This is what worked for me using jQuery
$(document).ready(function () {
var trail = window.location.href.substr(window.location.href.lastIndexOf("/")+1);
$(".en-link").find('a').attr('href', $(".en-link").find('a').attr('href') + trail);
$(".fr-link").find('a').attr('href', $(".fr-link").find('a').attr('href') + trail);
});
But also need to counter for subpages for press and media sections:
jQuery(function ($) {
$(document).ready(function () {
var trail = window.location.href.substr(window.location.href.lastIndexOf("/")+1);
var trailSub = window.location.href.substr(window.location.href.lastIndexOf("/")-5);
if (window.location.href.indexOf("press") != -1) {
$(".en-link").find('a').attr('href', $(".en-link").find('a').attr('href') + trailSub);
$(".fr-link").find('a').attr('href', $(".fr-link").find('a').attr('href') + trailSub);
}
else if (window.location.href.indexOf("media") != -1) {
$(".en-link").find('a').attr('href', $(".en-link").find('a').attr('href') + trailSub);
$(".fr-link").find('a').attr('href', $(".fr-link").find('a').attr('href') + trailSub);
}
else {
$(".en-link").find('a').attr('href', $(".en-link").find('a').attr('href') + trail);
$(".fr-link").find('a').attr('href', $(".fr-link").find('a').attr('href') + trail);
}
});
});