

- 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 use JavaScript to set cookies for multiple pages?
To set cookies for multiple pages, you need to set the path as −
;path=/
Example
The above will make your cookies to site cookie. You can try to run the following code to set cookies for multiple pages −
<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 + "; 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 Questions & Answers
- How to set multiple cookies in JavaScript?
- How to use JavaScript to set cookies for homepage only?
- How to use JavaScript to set cookies for a specific page only?
- How to use the same JavaScript in multiple content pages?
- How to set named cookies in JavaScript?
- How to set cookies expiry date in JavaScript?
- How can we use hub pages to find authoritative pages?
- How to set cookies in ReactJS?
- How to set cookies to expire in 1 hour in JavaScript?
- How to set cookies to expire in 30 minutes in JavaScript?
- How to create cookies in JavaScript?
- How to delete cookies in JavaScript?
- How to use Cookies in CGI in Perl?
- How to set Multiple Tests for a Request in Postman with JavaScript Method?
- What is the use of JavaScript cookies?
Advertisements