Cookie mit Button begrüßt Besucher





Quellcode
<html>
<head>
<script type="text/javascript">
function register(name)
{var curdate = new Date(); curdate.setMonth(curdate.getMonth() + 9); cookieExpires = curdate.toUTCString();
final_cookie = "Hans Busch=" + encodeURIComponent(name) + ";expires_on = " + cookieExpires; document.cookie = final_cookie;}
function getCookie(cookie_name) {var search_cookie = cookie_name + "="
if (document.cookie.length > 0) {start_position = document.cookie.indexOf(search_cookie)
if (start_position!= -1) {start_position += search_cookie.length
end_position = document.cookie.indexOf(";", start_position)
if (end_position == -1)
end_position = document.cookie.length
return (decodeURIComponent(document.cookie.substring(start_position, end_position))) } } }
</script>

<style type="text/css">Hier nichts.</style>
</head>

<body onload="checkCookie()">
<script type="text/javascript">
var username = getCookie("Hans Busch")
if (username) {document.write("Hallo ", username, ". Schön dich zu sehen")}
if (username == null) {
document.write("Du warst schon lange nicht mehr hier. ")
document.write("Wenn du in den nächsten neun Monaten auf diese Seite zurückkehrst, ");
document.write("wirst du namentlich gegrüßt.");
document.write('<form onsubmit = "return false">');
document.write('<p>Geben Sie ihren Namen ein: </p>');
document.write('<input type="text" name="username" size="40">');
document.write('<input type = "button" value= "Register"');
document.write('onClick="register(this.form.username.value); history.go(0)">');
document.write('</form>'); }
</script>
</body>

</html>