

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to get the cookies associated with a document in JavaScript?
Javascript has provided document object to deal with any kind of information regarding documents. This object has provided document.cookie to get the cookies associated with the particular document. This method won't disturb any other lines of code.
syntax
cookie = document.cookie;
Example
In the following example, document.cookie is used to get the cookie associated with the document and the result is displayed in the output as shown.
<html> <body> <p id="cookie"></p> <script> document.getElementById("cookie").innerHTML = "Cookies associated with this document: " + document.cookie; </script> </body> </html>
Output
Cookies associated with this document: __gads=ID=d8f23645916eff32:T=1559194976:S=ALNI_MZiHCQMqRpHFrUORCA63QNhEZSDFg; _ga=GA1.2.1225192854.1559194940; G_ENABLED_IDPS=google; qa_user_id=djl6Z3J3YkJWd2loN0ZzTEdrWTJjQT09; PHPSESSID=3e102fc373866clf69p2583m45; __utmz=55973678.1562912992.131.8.utmccn=(referral)|utmcsr=google.com|utmcct=/|utmcmd=referral; _gid=GA1.2.694316508.1564029750; editor_font_size=14; QASESSIONID=5d73npkehf89kqcdjg4fq571a6; __utmc=55973678; __atuvc=43%7C26%2C44%7C27%2C49%7C28%2C49%7C29%2C24%7C30; __utmb=55973678; __utma=55973678.1225192854.1559194940.1564137677.1564145427.177; _gat_gtag_UA_128776493_12=1
- Related Questions & Answers
- How to show name/value pairs of cookies in a document with JavaScript?
- How to access cookies using document object in JavaScript?
- How to get the number of forms in a document with JavaScript?
- How to get the data associated with the maximum id in a MySQL table?
- How to clear all cookies with JavaScript?
- How to create a session only cookies with JavaScript?
- Get the value associated with a given key in Java HashMap
- How to get a particular anchor in a document in JavaScript?
- How to get the entire document HTML as a string in JavaScript?
- How to display the title of a document with JavaScript?
- How to get the title and full URL of a document in JavaScript?
- How to use JavaScript to replace the content of a document with JavaScript?
- How to get the value associated with the http-equiv or name attribute in HTML?
- How to create cookies in JavaScript?
- How to delete cookies in JavaScript?
Advertisements