First thing, keep in mind that I never used Javascript by myself (only took some script who worked at 100%) and same for the Objet Programming (learned the programmation on Pascal, 12 years ago).
Now, I have to create a little online shop on German and French.
I made the functions to set the cookies whoo keep the language selected.
But now, I wanted at least one thing : If there isn't any cookie named "Language", create one and set it to french.
How can I do that?
My function :
function setCookie(sName, sValue) {
var expDate = new Date();
expDate.setTime(expDate.getTime() + (365 * 24 * 3600 * 1000)); // ici 1 an
document.cookie = sName + "=" + escape(sValue) + ";expires=" + expDate.toGMTString() + ";path=/";
}
and the page :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="./css/style.css" rel="stylesheet" media="all" type="text/css" />
<script type="text/Javascript" src="./javascript/cookie.js"></script>
<title></title>
<?php
require_once './includes/google_analytics.php';
?>
</head>
<body onload="setCookie('language','fr');">
<p>
Language : <a href="<?php echo $_SERVER['PHP_SELF']?>" onclick="setCookie('language','fr')">fr</a> /
<a href="<?php echo $_SERVER['PHP_SELF']?>" onclick="setCookie('language','de')">de</a>
</p>
<?php
require_once './includes/menu.php';
?>
<div id="contener">
<!-- --------------------------------------------- -->
<?php
require_once './includes/header.php';
?>
<!-- --------------------------------------------- -->
<!-- --------------------------------------------- -->
<?php
require_once './includes/footer.php';
?>
</div>
</body>
</html>
I wanted to do the test with the "onload".