Wednesday, 4 September 2013

Cookie handling through Javascript

Following Code will work only in mozilla...for chrome browser need to be handled explicitly

<html>
<head>

</head>

<body>
<button type "button"  onclick="z()">A</button>
<button type "button"  onclick="x()">B</button>
<p id="m">A 0</p>
<p id="g">B 0</p>

<script>
var b=document.cookie
document.write(b)
if(b=="")
{
var i=0
var j=0;
}
else
{
var a=document.cookie
var i=parseInt(a.charAt(0))
var j=parseInt(a.charAt(2))
}
function z()
{
i=i+1;
document.getElementById("m").innerHTML="A: "+i
document.cookie=i+" "+(j+0)
}
function x()
{
j=j+1;
document.getElementById("g").innerHTML="B: "+j
document.cookie=i+" "+(j+0)
}
</script>

</body>
</html>

No comments:

Post a Comment