Object Oriented Programming Articles

Page 78 of 589

How to secretly copy to clipboard JavaScript function in Chrome and Firefox?

Lokesh Badavath
Lokesh Badavath
Updated on 15-Mar-2026 1K+ Views

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 More

How to work with JavaScript Drag and drop for touch devices?

Lokesh Badavath
Lokesh Badavath
Updated on 15-Mar-2026 6K+ Views

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 More

How to fix Array indexOf() in JavaScript for Internet Explorer browsers?

Ramu Prasad
Ramu Prasad
Updated on 15-Mar-2026 513 Views

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 More

How to convert the image into a base64 string using JavaScript?

Arjun Thakur
Arjun Thakur
Updated on 15-Mar-2026 676 Views

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 More

How to understand JavaScript module pattern?

Lokesh Badavath
Lokesh Badavath
Updated on 15-Mar-2026 346 Views

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 More

How to get the body's content of an iframe in JavaScript?

Lokesh Badavath
Lokesh Badavath
Updated on 15-Mar-2026 24K+ Views

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 More

What is JavaScript AES Encryption?

Lokesh Badavath
Lokesh Badavath
Updated on 15-Mar-2026 15K+ Views

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 More

Is it safe to assume strict comparison in a JavaScript switch statement?

Priya Pallavi
Priya Pallavi
Updated on 15-Mar-2026 220 Views

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 More

How to disable browser's back button with JavaScript?

George John
George John
Updated on 15-Mar-2026 3K+ Views

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 More

How to perform Automated Unit Testing with JavaScript?

Chandu yadav
Chandu yadav
Updated on 15-Mar-2026 283 Views

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
Showing 771–780 of 5,881 articles
« Prev 1 76 77 78 79 80 589 Next »
Advertisements