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
Front End Technology Articles
Page 331 of 652
How can I pop-up a print dialog box using JavaScript?
To pop-up a print dialog box using JavaScript, use the window.print() method. This method opens the browser's print dialog, allowing users to select printing options like printer choice, page range, and paper size. Syntax window.print(); Basic Example Here's a simple example that opens the print dialog when a button is clicked: Print Dialog Example My Document This content will be printed when you click the print button. ...
Read MoreHow to create JavaScript objects using new operator?
The new operator in JavaScript creates instances of objects. It can be used with built-in constructors like Object(), Array(), or with custom constructor functions to create objects with specific properties and methods. Syntax let objectName = new ConstructorFunction(parameters); Using new with Object Constructor The most basic way is using new Object() to create an empty object, then add properties: var dept = new Object(); dept.employee ...
Read MoreHow to set multiple cookies in JavaScript?
In JavaScript, you can set multiple cookies by calling document.cookie multiple times. Each call adds a new cookie to the browser's cookie store. Unlike other properties, document.cookie doesn't overwrite existing cookies — it appends new ones. Basic Syntax for Multiple Cookies document.cookie = "cookie1=value1"; document.cookie = "cookie2=value2"; document.cookie = "cookie3=value3"; Example: Setting Multiple Cookies Here's a complete example showing how to add, list, and remove multiple cookies: var num = 1; ...
Read MoreHow can I show a euro or other HTML entity in JavaScript alert windows?
This tutorial will teach us to show a euro or other HTML entities in JavaScript alert windows. JavaScript provides three types of pop-up windows: Alert box, Confirm box, and Prompt box. The alert box displays information to users, such as welcome messages or notifications. The confirm box shows confirmation messages and returns true/false based on user choice. The prompt box collects input from users through a pop-up interface. Default JavaScript alert boxes only display plain text, so we need special techniques to show currency symbols and other HTML entities. We can use Unicode escape sequences, decimal codes, or ...
Read MoreHow can I delete all cookies with JavaScript?
To delete all cookies with JavaScript, you need to iterate through existing cookies and set their expiration date to the past. JavaScript doesn't provide a direct method to clear all cookies at once, so we must delete them individually. How Cookie Deletion Works Cookies are deleted by setting their expires attribute to a past date. When the browser sees an expired cookie, it automatically removes it from storage. Method 1: Basic Cookie Deletion This approach splits the cookie string and deletes each cookie by name: function deleteAllCookies() { var cookies ...
Read MoreHow to detect that JavaScript Cookies are disabled?
This tutorial will teach you how to detect if cookies are enabled or disabled on a website using JavaScript. Cookies are small text files stored on your computer that contain data. When a web server sends a web page to a browser, it terminates the connection and forgets about the user. Cookies solve the challenge of "how to remember information about the user" by storing data like usernames for subsequent visits. Cookies allow you to store user information between page visits. Your server transmits certain data to the visitor's browser in the form of a cookie, which may be ...
Read MoreHow to define methods for an Object in JavaScript?
Methods are functions that let an object perform actions or have actions performed on it. The key difference between a function and a method is that a function is a standalone unit of statements, while a method is attached to an object and can be referenced using the this keyword. Methods are used for everything from displaying object contents to performing complex mathematical operations on properties and parameters. Method 1: Defining Methods During Object Creation You can define methods directly when creating an object using object literal notation: let person = { ...
Read MoreWhat is the difference between new operator and object() constructor in JavaScript?
Both the new operator and Object() constructor are used to create objects in JavaScript, but they serve different purposes and contexts. The new Operator The new operator is used to create an instance of an object. It works with constructor functions to instantiate objects and automatically handles the object creation process. var department = new Object(); var books = new Array("C++", "Perl", "Java"); var day = new Date("December 1, 2017"); document.write("Department: " + typeof department + ""); document.write("Books: " + books + ""); document.write("Date: " + day + ""); ...
Read MoreHow to detect all active JavaScript event handlers?
JavaScript doesn't provide a built-in method to detect all active event handlers on a page. However, there are several approaches to identify event listeners attached to DOM elements. Using jQuery to Detect Event Handlers jQuery provides a convenient way to access event data for elements that have jQuery event handlers attached. Demo Text // Attach jQuery event handler ...
Read MoreWhat are secured cookies in JavaScript?
Secured cookies in JavaScript are cookies with special security attributes that protect against common web vulnerabilities. They use two main flags: Secure and HttpOnly to enhance security. What Makes a Cookie Secured? A secured cookie has two key attributes: Secure flag - Cookie is only sent over HTTPS connections HttpOnly flag - Cookie cannot be accessed via JavaScript The Secure Attribute The Secure attribute ensures cookies are only transmitted over encrypted HTTPS connections, preventing interception over unsecured HTTP. // Setting a secure cookie (server-side example) document.cookie = "sessionId=abc123; Secure; Path=/"; ...
Read More