Javascript Articles

Page 283 of 534

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

Smita Kapse
Smita Kapse
Updated on 15-Mar-2026 1K+ Views

In JavaScript, you can list all cookies on the current page using the document.cookie property. This property returns a string containing all cookies as semicolon-separated key-value pairs. Basic Cookie Retrieval The simplest way to get all cookies is to access document.cookie directly: // Set some sample cookies first document.cookie = "username=john; path=/"; document.cookie = "theme=dark; path=/"; ...

Read More

How to store large data in JavaScript cookies?

Nishtha Thakur
Nishtha Thakur
Updated on 15-Mar-2026 763 Views

JavaScript cookies have a size limit of approximately 4KB per cookie, making them unsuitable for storing large amounts of data directly. Here are several effective strategies to handle large data storage needs. Cookie Size Limitations Before exploring solutions, it's important to understand that: Each cookie is limited to ~4KB (4096 bytes) Browsers typically allow 20-50 cookies per domain Total storage per domain is usually limited to 4KB × number of cookies Method 1: Using Session IDs with Server Storage Store large data on the server and use a session ID in the cookie ...

Read More

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

Saurabh Jaiswal
Saurabh Jaiswal
Updated on 15-Mar-2026 753 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. Common Operations That Produce NaN console.log(Math.sqrt(-1)); // NaN console.log(0/0); // NaN console.log(parseInt("foo")); // NaN console.log("hello" * 2); ...

Read More

How to get a number value of a string in Javascript?

Nancy Den
Nancy Den
Updated on 15-Mar-2026 592 Views

To extract numeric values from strings in JavaScript, you have several approaches depending on your needs. The most common methods are using regular expressions with parseInt(), parseFloat(), or Number(). Using parseInt() with Regular Expression For extracting integers from strings containing mixed content, combine parseInt() with match() and a regex pattern: var myStr = "abcdef 30"; var num = parseInt(myStr.match(/\d+/)); console.log("Extracted number:", num); ...

Read More

Does HTML5 only replace the video aspects of Flash/Silverlight?

Lakshmi Srinivas
Lakshmi Srinivas
Updated on 15-Mar-2026 157 Views

HTML5 doesn't only replace video aspects of Flash/Silverlight—it provides comprehensive alternatives for graphics, animations, multimedia, and interactive content through several powerful technologies. What HTML5 Offers Beyond Video While HTML5's and elements replace Flash's multimedia capabilities, the element provides a complete drawing and animation platform using JavaScript. HTML5 Canvas Element The element creates a drawable region where you can render graphics, animations, and interactive content dynamically: Canvas Animation Example Here's a simple animation that demonstrates Canvas capabilities: const canvas = document.getElementById('animCanvas'); const ...

Read More

What is the shortest function of reading a cookie by name in JavaScript?

Rishi Rathor
Rishi Rathor
Updated on 15-Mar-2026 181 Views

The shortest way to read a cookie by name in JavaScript is using a one-line function that searches through document.cookie and extracts the specific value. Shortest Cookie Reader Function Here's the most concise function to read a cookie by name: Cookie Reader // Set some cookies first for testing document.cookie = "username=john; path=/"; document.cookie = "theme=dark; path=/"; ...

Read More

How to calculate the difference between two dates in JavaScript?

Jennifer Nicholas
Jennifer Nicholas
Updated on 15-Mar-2026 2K+ Views

To calculate the difference between two dates in JavaScript, use the getTime() method to get timestamps in milliseconds, then subtract one from the other. Basic Date Difference Calculation The getTime() method returns the number of milliseconds since January 1, 1970. By subtracting two timestamps, you get the difference in milliseconds. var dateFirst = new Date("11/25/2017"); var dateSecond = new Date("11/28/2017"); // time difference in milliseconds var timeDiff = Math.abs(dateSecond.getTime() - dateFirst.getTime()); // days difference var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24)); // display result console.log("Difference: " ...

Read More

innerHTML adds text but not HTML tags

Vrundesha Joshi
Vrundesha Joshi
Updated on 15-Mar-2026 272 Views

When using innerHTML in JavaScript, you need to ensure proper HTML string formatting and correct assignment. The innerHTML property parses and renders HTML tags when set correctly. Common Issue: Building HTML Strings When concatenating HTML strings with +=, make sure to build the complete HTML structure before assigning it to innerHTML. var myNum = [1, 2, 3]; var myStr; myStr = ""; for(var a in myNum) { myStr += "" + myNum[a] + ""; } myStr += ""; document.getElementById("numberList").innerHTML = myStr; • 1 ...

Read More

What is the maximum size of a web browser's cookies value?

Daniol Thomas
Daniol Thomas
Updated on 15-Mar-2026 5K+ Views

The maximum size of cookies varies across different web browsers. Understanding these limitations is crucial for web developers to ensure proper cookie handling and avoid data loss. Browser Cookie Limits Web Browser Maximum Cookies per Domain Maximum Size per Cookie ...

Read More

Drop target listens to which events in HTML5?

Lakshmi Srinivas
Lakshmi Srinivas
Updated on 15-Mar-2026 181 Views

To accept a drop in HTML5, a drop target must listen to at least three essential events that handle the drag-and-drop sequence. Required Events for Drop Targets The dragenter event, which is used to determine whether the drop target is to accept the drop. If the drop is to be accepted, then this event has to be canceled. The dragover event, which is used to determine what feedback is to be shown to the user. If the event is canceled, then the feedback (typically the cursor) is updated based on the dropEffect attribute's value. Finally, the drop ...

Read More
Showing 2821–2830 of 5,340 articles
« Prev 1 281 282 283 284 285 534 Next »
Advertisements