Course Hive
Search

Welcome

Sign in or create your account

Continue with Google
or
JavaScript cookie attributes
Play lesson

JavaScript Tutorial - JavaScript cookie attributes

4.0 (0)
13 learners

What you'll learn

This course includes

  • 12.3 hours of video
  • Certificate of completion
  • Access on mobile and TV

Summary

Keywords

Full Transcript

Link for all dot net and sql server video tutorial playlists http://www.youtube.com/user/kudvenkat/playlists Link for slides, code samples and text version of the video http://csharp-video-tutorials.blogspot.com/2015/02/javascript-cookie-attributes.html Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help. https://www.youtube.com/channel/UC7sEwIXM_YfAMyonQCrGfWA/?sub_confirmation=1 In this video we will discuss some of the optional cookie attribute values that can be specified when creating a cookie. This is continuation to Part 67, please watch Part 67 of JavaScript tutorial before proceeding. Optional Cookie Attributes expires max-age domain path secure The following code creates a cookie that expires as soon as the browser is closed document.cookie = "color=red"; expires and max-age attributes : If you want to create a persistent cookie, that is a cookie that is not deleted after the browser is closed either use expires or max-age attributes document.cookie = "color=red;expires=Fri, 5 Aug 2016 01:00:00 UTC"; OR document.cookie = "color=red;max-age=" + (60 * 60 * 24 * 30) + ";"// Creates a cookie that expires in 30 days What is the difference between expires and max-age attributes With expires attribute you set an expiry date. The expires attribute is obsolete. Very few modern browsers support this attribute. Internet Explorer is one of them. With max-age attribute you specify the expiry time in seconds. Most modern browsers support this attribute except Internet Explorer. If you want to create a persistent cookie that works in IE and all the other browsers then specify both expires and max-age attributes. domain attribute : Specifies the doamin for which the cookie is valid. If you specify the doamin as PragimTech.Blog.com then that cookie will be valid only for that sub-domain. It will not be valid for PragimTech.com. If you want a cookie to be valid for all sub-domains of PragimTech.com then specify domain=PragimTech.com. So this cookie will be valid for PragimTech.com PragimTech.Blog.com PragimTech.Blog.KudVenkat.com path attribute : By default cookies are valid only for web pages in the directory of the current web page that stored them, as well as its descendants. Example : The following diagram shows the directory structure of a web application // JavaScript cookie attributes.png If a cookie is set by http://localhost/Home/Page2.htm, it will be valid for http://localhost/Home/SubFolder/Page1.htm but not for http://localhost/Page3.htm If you want to create a cookie that is valid across all your pages in your website, then set the path attribute to the root of your web directory, that is, "/". document.cookie = "color=red;max-age=" + (60 * 60 * 24 * 30) + ";path=/"; secure attribute : secure attribute specifies that the cookie is secure and is only used over HTTPS protocol which ensures that the cookie is always encrypted when transmitting from client to server.

Course Hive

Continue this lesson in the app

Install CourseHive on Android or iOS to keep learning while you move.

FAQs

Course Hive
Download CourseHive
Keep learning anywhere