- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 create domain-based cookies using JavaScript?
To create a domain-based cookie, set the domain and path attribute on your cookie, like −
domain=.example.com
Example
You can try to run the following code to learn how to create domain-based cookies −
<html> <head> <script> <!-- function WriteCookie() { if( document.myform.customer.value == "" ){ alert("Enter some value!"); return; } cookievalue= escape(document.myform.customer.value) + ";"; document.cookie = "name=" + cookievalue + "; domain=.example.com;path=/"; document.write ("Setting Cookies : " + "name=" + cookievalue ); } //--> </script> </head> <body> <form name = "myform" action = ""> Enter name: <input type="text" name="customer"/> <input type="button" value="Set Cookie" onclick="WriteCookie();"/> </form> </body> </html>
- Related Articles
- How to create cookies in JavaScript?
- How to create a session only cookies with JavaScript?
- How to access cookies using document object in JavaScript?
- How to delete cookies in JavaScript?
- How to list down all the cookies by name using JavaScript?
- How to clear all cookies with JavaScript?
- How to set named cookies in JavaScript?
- How to set multiple cookies in JavaScript?
- How to set cookies expiry date in JavaScript?
- How to detect that JavaScript Cookies are disabled?
- How to store large data in JavaScript cookies?
- How to create animations using JavaScript?
- JavaScript - How to create nested unordered list based on nesting of array?
- How to create SVG graphics using JavaScript?
- How to Create Fullscreen API using JavaScript?

Advertisements