I have a Javascript code to translate a few parts of my HTML page in other languages. You can read a few more details about it in another question I asked here: Multilanguage static website with JQuery
I have the same Javascript code in every HTML page in my website. In Home page (www.mywebsite.com) works, but in any other longer path (www.mywebsite.com/anotherpage) doesn't work. The weird here is that the code is totally missing from the source code of the page (right click --> view source code)
Here is a part of the code (the whole page is huge and I cannot paste it all)
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Le styles -->
<link href="./static/css/bootstrap.min.css" rel="stylesheet">
<link href="./static/css/slider.css" rel="stylesheet">
<link rel="stylesheet" href="./static/css/font-awesome.css" />
<link rel="stylesheet" href="./static/css/jquery-ui.css" />
</head>
<body>
....
</body>
<script src="./static/js/jquery.js"></script>
<script src="./static/js/bootstrap.min.js"></script>
<script src="./static/js/bootstrap-slider.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="./static/js/jquery.dataTables.min.js"></script>
! a few other script codes that works without a problem in this part !
! this is the one that is missing from the code
<script type="text/javascript">
function getCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') c = c.substring(1, c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
}
return null;
}
$(function() {
var language = getCookie("language");
if (language == null) {
var language = 'English'
}
alert(language)
$.ajax({
url: './static/languages/languages.xml',
success: function(xml) {
$(xml).find('translation').each(function(){
var id = $(this).attr('id');
var text = $(this).find(language).text();
$("." + id).html(text);
});
}
});
});
</script>
I have tried to put the script code on the top of the page, but I have the same problem. I have tried to put the full url on xml file without a success. I don't have any error on the console and the script doesn't run neither it is on the page source code.
SOLVED:
If I load the script code from an external file, then it works. The external file has exactly the same code, so it wasn't a typographic error.