Found 6685 Articles for Javascript

How to create a session only cookies with JavaScript?

Vrundesha Joshi
Updated on 16-Jun-2020 12:15:34

807 Views

To create a session only cookie, you need to set the expiration date of the cookie to be some years ahead. You need to set the expire attribute −current time + 5 yearsThe expire attribute shows the date the cookie will expire. If this is blank, the cookie will expire when the visitor quits the browser.Note − Do not consider removing the expire value to create a session only cookie. This won’t work. Set the expire attribute to the future date.

What is a NaN property of a Number object in JavaScript?

Saurabh Jaiswal
Updated on 05-Jan-2023 15:27:18

468 Views

In JavaScript, the NaN property is a special value that represents "Not a Number". It is a property of the Number object and can be accessed using Number.NaN. The NaN property is usually produced as a result of an operation that cannot produce a meaningful result. For example, dividing 0 by 0 or trying to parse an invalid number will both produce NaN. Here are a few examples of operations that will produce NaN − Math.sqrt(-1); // NaN 0/0; // NaN parseInt("foo"); // NaN It ... Read More

How to store large data in JavaScript cookies?

Nishtha Thakur
Updated on 16-Jun-2020 12:03:27

502 Views

To store large values in JavaScript cookies, try the following possibilities −Create a "session id" and save the settings in a database. Then store the session id in the cookie.Store the indexes of the selected items. Let’s say the selected items are the first 20 items on the list −P[0,19]Create a table to store cookies data such as −[ data_id , data , data_create , date_expire ]Store data_id in a table and when a user visits, get the data_id in cookies.

How can I list all cookies on the current page with JavaScript?

Smita Kapse
Updated on 16-Jun-2020 12:01:38

948 Views

While creating a cookie, use the “path” parameter. The path to the directory or web page set the cookie. This may be blank if you want to retrieve the cookie from the current page. By default, the cookie belongs to the current page.ExampleTo list all cookies for the current page, try the following code −Live Demo                    function ReadCookie() {             var allcookies = document.cookie;             document.write ("All Cookies : " + allcookies );             // Get all the cookies pairs in an array             cookiearray = allcookies.split(';');             // Now take key value pair out of this array             for(var i=0; i

How to create domain-based cookies using JavaScript?

Anvi Jain
Updated on 16-Jun-2020 11:58:59

213 Views

To create a domain-based cookie, set the domain and path attribute on your cookie, like −domain=.example.comExampleYou can try to run the following code to learn how to create domain-based cookies −Live Demo                                                  Enter name:                    

How to use JavaScript to set cookies for multiple pages?

Nitya Raut
Updated on 16-Jun-2020 11:57:22

1K+ Views

To set cookies for multiple pages, you need to set the path as −;path=/ExampleThe above will make your cookies to site cookie. You can try to run the following code to set cookies for multiple pages −Live Demo                                                  Enter name:                    

What is the maximum value represented by Number object in JavaScript?

Smita Kapse
Updated on 17-Jun-2020 06:20:45

247 Views

The largest possible value a number in JavaScript can have 1.7976931348623157E+308. The Number.MAX_VALUE property belongs to the static Number object. It represents constants for the largest possible positive numbers that JavaScript can work with.ExampleYou can try to run the following code to get the maximum value represented by Number object −Live Demo                                         Click the following to see the result:                          

How to use JavaScript to set cookies for a specific page only?

Abhishek Kumar
Updated on 21-Sep-2022 07:58:57

2K+ Views

We can set cookies for a specific page only using JavaScript. We use the path attribute of the document.cookie property to set the cookie on a specific webpage. Cookies are small text files (4 KB) that store important information such as username, email, session id, and other preferences that help customize the webpage for a particular user. Something so trivial as this is a user preference and thus can be conveniently stored in a corresponding cookie file. The pathname property of the Window location returns a string containing the path of the current webpage. The path is basic information about ... Read More

How to use JavaScript to set cookies for homepage only?

Vrundesha Joshi
Updated on 09-Jan-2020 10:33:42

243 Views

To set cookies for a homepage, add the page to the homepage itself.ExampleYou can try to run the following code to set cookiesLive Demo                                                  Enter name:                    

How to list down all the cookies by name using JavaScript?

Rishi Rathor
Updated on 09-Jan-2020 10:32:39

161 Views

To lists down all the cookies by name, use the cookies pairs in an array. After that, you need to get the key value pair out of this array.ExampleYou can try to run the following code to list all the cookiesLive Demo                                                   click the following button and see the result:                    

Advertisements