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 366 of 534
HTML5 and Amazon S3 Multi-Part uploads
Amazon S3 multi-part uploads allow you to upload large files in smaller chunks, providing better reliability and performance. When combined with the HTML5 File API, you can create powerful client-side upload functionality. Overview of S3 Multi-Part Uploads Amazon S3 multi-part upload is a feature that enables you to upload a single object as a set of parts. Each part is a contiguous portion of the object's data, and you can upload these parts independently and in any order. How HTML5 File API Works with S3 The HTML5 File API provides interfaces for accessing files from web ...
Read MoreFind even odd index digit difference - JavaScript
We are required to write a JavaScript function that takes in a number and returns the difference of the sums of the digits at even place and the digits at odd place. Understanding the Problem Given a number, we need to: Sum all digits at even positions (0, 2, 4, ...) Sum all digits at odd positions (1, 3, 5, ...) Return the absolute difference between these sums Example For the number 345336: Position 0: 6 (even) Position 1: 3 (odd) Position 2: 3 (even) Position 3: 5 (odd) Position 4: 4 (even) ...
Read MoreWebsocket for binary transfer of data & decode with HTML5
WebSockets can handle binary data transfer using base64 encoding/decoding. Modern browsers provide built-in methods window.btoa() for encoding and window.atob() for decoding base64 data. Base64 Encoding for Binary Transfer When transferring binary data through WebSockets, encode it as base64 on the client side before sending: // Create WebSocket connection const socket = new WebSocket('ws://localhost:8080'); // Convert ...
Read MoreDetection on clicking bezier path shape with HTML5
To detect clicks on Bezier path shapes in HTML5 Canvas, you need to use pixel-based detection since Canvas doesn't have built-in shape hit testing. This technique draws the shape invisibly and checks if the clicked pixel contains color data. How Pixel-Based Detection Works The method involves drawing the Bezier shape to a hidden canvas context, then checking if the clicked coordinates contain any pixels. If the alpha channel is greater than 0, the click hit the shape. Complete Click Detection Example const canvas = document.getElementById('myCanvas'); const ctx = canvas.getContext('2d'); // Sample Bezier ...
Read MoreHow to prevent text select outside HTML5 canvas on double-click?
When users double-click on or near an HTML5 canvas element, browsers may inadvertently select surrounding text. This creates a poor user experience, especially in interactive applications. Here's how to prevent this behavior. The Problem Double-clicking near a canvas element can trigger text selection in surrounding elements, highlighting unwanted text and disrupting the user interface. Solution: Disable Text Selection Set the onselectstart event handler to return false, which prevents the browser from starting text selection on the canvas element. var canvas = document.getElementById('myCanvas'); // Prevent text selection on double-click canvas.onselectstart = ...
Read MoreSum all duplicate value in array - JavaScript
We are required to write a JavaScript function that takes in an array of numbers with duplicate entries and sums all the duplicate entries to one index. For example − If the input array is − const input = [1, 3, 1, 3, 5, 7, 5, 4]; Then the output should be − const output = [2, 6, 7, 10, 4]; Using Map to Track and Sum Duplicates The most efficient approach is to use a Map to count occurrences and then multiply each unique value by its count: ...
Read MoreCross-browser drag-and-drop HTML file upload?
Cross-browser drag-and-drop file upload can be challenging due to browser differences. Modern browsers support the HTML5 File API, while legacy browsers require fallback solutions. HTML5 Drag and Drop API Modern browsers support native drag-and-drop using the HTML5 File API: Drop files here const dropZone = document.getElementById('dropZone'); // Prevent default drag behaviors ['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => { dropZone.addEventListener(eventName, preventDefaults, false); }); function preventDefaults(e) { e.preventDefault(); e.stopPropagation(); } // Handle drop dropZone.addEventListener('drop', handleDrop, false); ...
Read MoreHTML5 file uploading with multiple progress bars
HTML5 provides native file upload capabilities with progress tracking. When uploading multiple files, you can create individual progress bars for each file by leveraging the XMLHttpRequest progress events. The Challenge The main challenge is associating each XMLHttpRequest with its corresponding progress bar element. This requires storing a reference to the list item in the XMLHttpRequest object. Setting Up the Progress Tracking To track progress for multiple files, you need to bind each XMLHttpRequest to its corresponding list item element before starting the upload: Multiple File Upload with ...
Read MoreHTML5 File API readAsBinaryString reads files as much larger and different than files on disk
When using HTML5 File API's readAsBinaryString() method, the resulting binary string can appear much larger than the original file due to character encoding issues and inefficient string representation of binary data. The Problem with readAsBinaryString The readAsBinaryString() method converts binary data to a string format, which can cause size inflation and encoding problems. This is especially problematic when manually creating multipart/form-data requests. Recommended Solution: Use FormData with File Objects Instead of reading files as binary strings, use FormData with the original File objects. This preserves the file's binary integrity and size. ...
Read MoreInverting signs in array - JavaScript
We are required to write a JavaScript function that takes in an array of positive as well as negative Numbers and changes the positive numbers to corresponding negative numbers and the negative numbers to corresponding positive numbers in place. Let's write the code for this function — Example Following is the code — const arr = [12, 5, 3, -1, 54, -43, -2, 34, -1, 4, -4]; const changeSign = arr => { arr.forEach((el, ind) => { arr[ind] *= -1; ...
Read More