JavaScript Cookies Path

You are Here:

JavaScript Cookies Path

The path parameter tells the browser what path the cookie belongs to. By default, the cookie belongs to the current page.

Global Path

Use "path=/" to set a cookie (name) to all pages under wikimass.com.

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <script> var name = "Steve"; document.cookie = "username="+name+";path=/"; document.write("Cookie written"); </script> </body> </html>

Directory Path

Use "path=/js" to set a cookie (userage) to javascript tutorials only.

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <script> var age = "25"; document.cookie = "userage="+age+";path=/js"; document.write("Cookie written"); </script> </body> </html>

Folder Path

Use "path=/js/cookies-path" to set a cookie (userweight) to this page and its sub pages (example programs of this page) only.

This is Default, when path is not specified.

HTML Online Editor
<!DOCTYPE html> <html> <body> <script> var weight = "75 kg"; document.cookie = "userweight="+weight+";path=/js/cookies-path"; document.write("Cookie written"); </script> </body> </html>

Reminder

Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in JavaScript.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author