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
Object Oriented Programming Articles
Page 78 of 589
How to secretly copy to clipboard JavaScript function in Chrome and Firefox?
In JavaScript, you can programmatically copy text to the clipboard without user interaction using different methods. This tutorial shows how to implement "secret" clipboard copying that works silently in the background. We'll explore both the legacy execCommand() method and the modern Clipboard API for copying text to clipboard programmatically. Using execCommand() Method (Legacy) The execCommand() method was traditionally used for clipboard operations. Here's a basic implementation: Copy text ...
Read MoreHow to work with JavaScript Drag and drop for touch devices?
JavaScript drag and drop functionality provides an intuitive way to move elements within web pages. While the HTML5 Drag and Drop API works well on desktop, touch devices require additional handling to ensure proper functionality. Basic Drag and Drop Concepts To make an element draggable in HTML5, add the draggable="true" attribute to the element. By default, images and text selections are draggable, but other elements need this attribute. Drag me Drag and Drop Events The drag and drop process involves two sets of events: Events on draggable elements: dragstart - Fires ...
Read MoreHow to fix Array indexOf() in JavaScript for Internet Explorer browsers?
Internet Explorer versions 8 and below don't support the Array.indexOf() method. This article shows how to fix this compatibility issue using polyfills and jQuery alternatives. The Problem In modern browsers, indexOf() returns the first index of an element in an array, or -1 if not found. However, IE8 and earlier throw an error when you try to use this method. Method 1: Using Array Polyfill Add this polyfill to support indexOf() in older IE browsers: Method 2: Using jQuery.inArray() jQuery provides a cross-browser alternative with jQuery.inArray(): // Syntax: ...
Read MoreHow to convert the image into a base64 string using JavaScript?
To convert an image into a base64 string using JavaScript, you can use the FileReader API for local files or combine XMLHttpRequest with FileReader for remote images. Base64 encoding represents binary image data as a text string, making it useful for embedding images directly in HTML or CSS. Method 1: Converting Local Image Files For user-uploaded files, use the FileReader API with an input element: document.getElementById('imageInput').addEventListener('change', function(e) { ...
Read MoreHow to understand JavaScript module pattern?
The JavaScript Module Pattern is a design pattern that encapsulates private and public methods and variables within a single object. It provides a way to create modular, maintainable code while avoiding global namespace pollution. What is the Module Pattern? The Module pattern uses Immediately Invoked Function Expressions (IIFE) to create a closure that contains private variables and functions. It returns an object with public methods that can access these private elements. Why Use the Module Pattern? Maintainability − Modules are self-contained and reduce dependencies, making code easier to maintain and improve independently. Namespace Protection − ...
Read MoreHow to get the body's content of an iframe in JavaScript?
To get the body's content of an iframe in JavaScript, you need to access the iframe element first, then navigate to its document and retrieve the body content. This requires the iframe to be from the same origin due to browser security policies. Basic Approach First, get the iframe element using document.getElementById(), then access its content through contentWindow.document or contentDocument: Get Iframe Content Get Iframe Content ...
Read MoreWhat is JavaScript AES Encryption?
AES (Advanced Encryption Standard) is a symmetric encryption algorithm that uses the same key to encrypt and decrypt data. In JavaScript, we can implement AES encryption using libraries like CryptoJS to secure sensitive information in web applications. What is AES Encryption? AES is a widely adopted encryption standard that provides strong security for data protection. It's called "symmetric" because the same key is used for both encryption and decryption processes. This algorithm is commonly used in messaging applications like WhatsApp and Signal to ensure secure communication. How AES Works The encryption process involves converting plain text ...
Read MoreIs it safe to assume strict comparison in a JavaScript switch statement?
JavaScript switch statements use strict comparison (===) to match cases, not loose comparison (==). This means both value and type must match exactly. Understanding Switch Comparison Let's test this with a simple example to see which case matches: switch(1) { case '1': alert('Switch comparison: Not Strict.'); break; case 1: alert('Switch comparison: Strict.'); break; default: alert('Default'); } ...
Read MoreHow to disable browser's back button with JavaScript?
To disable the browser's back button, you can use JavaScript's history.forward() method to prevent users from navigating backward. This technique forces the browser to stay on the current page when the back button is clicked. Basic Approach The core idea is to push the current page forward in history whenever the user tries to go back: Disable Browser Back Button Main Page Next Page ...
Read MoreHow to perform Automated Unit Testing with JavaScript?
To perform automated unit testing in JavaScript, Unit.js is a cross-platform open-source unit testing framework that provides a simple and intuitive API for testing JavaScript applications. What is Unit.js? Unit.js is a JavaScript testing framework that works in both Node.js and browsers. It offers a fluent interface for writing readable test assertions and supports various testing patterns. Basic Syntax Unit.js uses a chainable syntax where you specify the data type and then chain assertion methods: test.dataType(value).assertionMethod(expectedValue); Simple String Testing Example Here's a basic example of testing a string value: ...
Read More