Found 6710 Articles for Javascript

How can I store JavaScript objects in cookies?

Shubham Vora
Updated on 09-Aug-2022 14:23:20

12K+ Views

This tutorial will teach us to store JavaScript objects into the cookies. The cookies are the information of website visitors stored in the text files. There is a particular mechanism to store the cookies of users' browsers. When new visitors visit the website, the server generates the text and sends it to the user. After that, when users allow access to the web page to retrieve the cookies, the server stores all user information in the text files. Cookies store the user’s search history or other information for a better experience. For example, Google stores the user’s search history to ... Read More

How to create JavaScript objects using object() constructor?

Jennifer Nicholas
Updated on 16-Jun-2020 13:53:02

371 Views

A constructor is a function that creates and initializes an object. JavaScript provides a special constructor function called Object() to build the object. The return value of the Object() constructor is assigned to a variable.The variable contains a reference to the new object. The properties assigned to the object are not variables and are not defined with the var keyword.ExampleYou can try to run the following code to learn how to work with JavaScript objects with object() constructor −Live Demo           User-defined objects                var book = new Object(); ... Read More

How to detect all active JavaScript event handlers?

Nishtha Thakur
Updated on 09-Jan-2020 10:20:19

781 Views

The simplest solution is to use jQuery to detect all active JavaScript event handlers.ExampleYou can try to run the following code to detect active event handlersLive Demo                          var myEvent = $("#demo");          myEvent.mouseover(function() {});          $.each(myEvent.data("events"), function(i, e) {             alert(i);          });                     Demo Text    

What is the difference between new operator and object() constructor in JavaScript?

Rishi Rathor
Updated on 17-Jun-2020 06:09:54

1K+ Views

The new operatorThe new operator is used to create an instance of an object. To create an object, the new operator is followed by the constructor method.In the following example, the constructor methods are Object(), Array(), and Date(). These constructors are built-in JavaScript functions.var department = new Object(); var books = new Array("C++", "Perl", "Java"); var day = new Date(“December 1, 2017");The object() constructorA constructor is a function that creates and initializes an object. JavaScript provides a special constructor function called Object() to build the object. The return value of the Object() constructor is assigned to a variable.The variable contains ... Read More

What are the differences between JavaScript and PHP cookies?

Anvi Jain
Updated on 03-Oct-2019 08:09:22

803 Views

JavaScript CookiesUsing JavaScript cookies is the most efficient method of remembering and tracking preferences, purchases, commissions, and other information required for better visitor experience or site statistics.PHP CookiesCookies are text files stored on the client computer and they are kept for tracking purpose. PHP transparently supports HTTP cookies.How JavaScript cookies work?Your server sends some data to the visitor's browser in the form of a cookie. The browser may accept the cookie. If it does, it is stored as a plain text record on the visitor's hard drive. Now, when the visitor arrives at another page on your site, the browser ... Read More

How to define methods for an Object in JavaScript?

Nancy Den
Updated on 03-Oct-2019 08:07:09

173 Views

Methods are the functions that let the object do something or let something is done to it. There is a small difference between a function and a method – at a function is a standalone unit of statements and a method is attached to an object and can be referenced by this keyword.Methods are used for everything from displaying the contents of the object to the screen to performing complex mathematical operations on a group of local properties and parameters. Here’s an example showing how to use the write() method of the document object to write any content on the document.document.write("This ... Read More

How to detect that JavaScript Cookies are disabled?

Shubham Vora
Updated on 30-Aug-2022 06:38:50

5K+ Views

This tutorial will teach you how to detect if cookies are enabled or disabled on a website using JavaScript. Cookies are small text files on your computer that contain data. A web server terminates the connection after sending a web page to a browser and completely forgets about the user. The challenge of "how to remember information about the user" led to the invention of cookies. A cookie may contain the name of a user who visits a website. The cookie "remembers" the user's name for the subsequent visit to the website. Cookies allow you to store user information on ... Read More

How can I delete all cookies with JavaScript?

Vrundesha Joshi
Updated on 03-Oct-2019 08:06:06

1K+ Views

To delete all cookies with JavaScript, you can try to run the following code. Here, we’re using an array and the split() method to get all the cookies and finally delete themExampleLive Demo                    var num = 1;          function addCookie(){             document.cookie = num+" = "+num;             num++;          }          function listCookies(){             var result = document.cookie;             document.getElementById("list").innerHTML = result;          }          function removeCookies() {             var res = document.cookie;             var multiple = res.split(";");             for(var i = 0; i < multiple.length; i++) {                var key = multiple[i].split("=");                document.cookie = key[0]+" =; expires = Thu, 01 Jan 1970 00:00:00 UTC";             }          }                     ADD       LIST COOKIES       REMOVE       Cookies List          

How to create object properties in JavaScript?

Abhishek
Updated on 31-Oct-2022 09:06:45

438 Views

JavaScript object properties are the keys inside the body of a JavaScript object. Object properties can be any of the three primitive data types, or any of the abstract data types, such as another object. Object properties are usually variables used internally in the object's methods, but can also be globally visible variables that are used throughout the page. These properties can either be statically typed by the programmer at the time of object declaration, or they can be modified or created later according to the need. There are two ways of creating or adding properties to a JavaScript object ... Read More

How can I show a euro or other HTML entity in JavaScript alert windows?

Shubham Vora
Updated on 10-Aug-2022 11:42:56

1K+ Views

This tutorial will teach us to show a euro or HTML entity in JavaScript alert Window. There are three pop-up windows in JavaScript. Alert box, Confirm box, and Prompt box. The alert box is useful to show some information to the user, such as a welcome message or user’s info. It contains the ok button, and when the user clicks on that, it closes. The confirm box is used to show the confirmation message. In many applications, you have seen that when you try to delete something, it shows the confirmation message. When you click on the ok, it returns ... Read More

Advertisements