The cookie
property sets or gets
all name/value pairs of cookies in the current document.
cookie |
Yes | Yes | Yes | Yes | Yes |
document.cookie
A string containing the name/value pairs of cookies in the document.
The following code shows how to get the cookies associated with the current document.
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<!-- w w w. j a v a 2s . com-->
<script>
function myFunction()
{
var x=document.getElementById("demo");
x.innerHTML="Cookies associated with this document: " + document.cookie;
}
</script>
</body>
</html>
The code above is rendered as follows: