Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Javascript Articles
Page 500 of 534
How to set a cookie and get a cookie with JavaScript?
JavaScript cookies allow you to store small pieces of data in the user's browser. You can set cookies using document.cookie and retrieve them by parsing the same property. Setting Cookies The simplest way to create a cookie is to assign a string value to the document.cookie object: document.cookie = "key1=value1;key2=value2;expires=date"; The "expires" attribute is optional. If you provide this attribute with a valid date or time, the cookie will expire on that date and the cookie's value will no longer be accessible. Example: Setting a Cookie This example sets a customer name ...
Read MoreHow to set JavaScript Cookie with no expiration date?
In this tutorial, we will learn how to set JavaScript cookies with no expiration date. Cookies are small data files stored by web browsers that help websites remember user preferences and track behavior. When a cookie has no expiration date, it becomes a session cookie that lasts until the browser is closed. Understanding Cookie Expiration The expires attribute in JavaScript cookies is optional. If you don't specify an expiration date, the cookie will automatically expire when the browser session ends (when the user closes the browser). This type of cookie is called a session cookie. Syntax for ...
Read MoreHow to set src to the img tag in html from the system drive?
To use an image on a webpage, use the tag. The tag allows you to add image source, alt, width, height, etc. The src is to add the image URL. The alt is the alternate text attribute, which is text that is visible when the image fails to load. With HTML, you can add the image source as the path of your system drive. For that, add the src attribute as a link to the path of system drive where the image is stored. For example, file:///D:/images/logo.png Important Security and Browser Limitations Note: Modern browsers restrict ...
Read MoreHow do I print Unicode characters in the console using JavaScript?
In this article, we will learn how to print Unicode characters in the console using JavaScript. Unicode assigns a unique number (code point) to each character, enabling consistent representation across different platforms and languages. Unicode is a universal character encoding standard that includes letters from most writing systems, punctuation marks, mathematical symbols, technical symbols, arrows, emoji, and other symbols. JavaScript provides several ways to work with Unicode characters in strings and console output. Using Escape Sequences JavaScript supports Unicode escape sequences to represent characters using their code point numbers. The most common format uses \u followed by ...
Read MoreHow do I print a message to the error console using JavaScript?
To print messages to the browser console in JavaScript, use the console object. Different methods display messages with varying styles and importance levels. Basic Console Methods Here are the main console methods for displaying messages: console.log("This is a regular message"); console.error("This is an error message"); console.warn("This is a warning message"); console.info("This is an info message"); This is a regular message This is an error message (displayed in red) This is a warning message (displayed in yellow/orange) This is an info message (displayed in blue) Error Console Specifically To print specifically ...
Read MoreHow to access cookies using document object in JavaScript?
In JavaScript, you can access and read cookies using the document.cookie property. This property returns a string containing all cookies stored in the browser for the current domain. The document.cookie string contains a list of name=value pairs separated by semicolons, where each name represents a cookie name and its corresponding value is the cookie's string value. In this article, we will learn how to access cookies using the document object in JavaScript. Syntax document.cookie Return Value: A string containing all cookies for the current domain, formatted as semicolon-separated name=value pairs. Reading All ...
Read MoreHow do I print debug messages in the Google Chrome JavaScript Console?
To print debug messages in the Google Chrome JavaScript Console, you can use various console methods. These methods help you output different types of information for debugging purposes. Setting Up Console Compatibility First, ensure console methods exist to prevent errors in older browsers: if (!window.console) console = {}; console.log = console.log || function(){}; console.warn = console.warn || function(){}; console.error = console.error || function(){}; Basic Console Methods The most commonly used console methods in Chrome are: // Basic logging console.log("This is a general log message"); // Warning message console.warn("This is a ...
Read MoreHow to clear all cookies with JavaScript?
In this tutorial, we will learn to clear all cookies using JavaScript. Cookies are text data stored in the browser that help websites remember user information like usernames, authentication tokens, and preferences. When a user visits a webpage for the first time, it retrieves user information from the server and stores it as cookies in the browser. On subsequent visits, the webpage can access this stored data instead of making server requests, making the application faster and more efficient. Modern browsers typically allow cookies up to 4KB in size, with limits on the total number: Chrome allows around ...
Read MoreHow to set cookies expiry date in JavaScript?
Setting an expiration date for cookies allows them to persist beyond the current browser session. Without an expiration date, cookies are deleted when the browser closes. You can set the expiry date using the expires attribute in the cookie string. Syntax document.cookie = "name=value; expires=date; path=/"; Setting Cookie with 1 Month Expiry Here's how to create a cookie that expires after one month: function WriteCookie() { var now = new Date(); ...
Read MoreHow to create cookies in JavaScript?
Using cookies is the most efficient method of remembering and tracking preferences, purchases, commissions, and other information required for better visitor experience or site statistics. The simplest way to create a cookie is to assign a string value to the document.cookie object, which looks like this: document.cookie = "key1=value1;key2=value2;expires=date"; Here the expires attribute is optional. If you provide this attribute with a valid date or time, then the cookie will expire on a given date or time and thereafter, the cookies' value will not be accessible. Note − Cookie values may not include semicolons, ...
Read More