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 371 of 534
Using FFMPEG with HTML5 for online video hosting
HTML5 introduced the native element, enabling browsers to play videos without plugins like Flash. FFMPEG is a powerful command-line tool that can convert videos into HTML5-compatible formats for seamless web streaming. HTML5 Video Formats Modern browsers support three main video formats: Format Codec Browser Support MP4 ...
Read MoreReplacing upperCase and LowerCase in a string - JavaScript
We are required to write a JavaScript function that takes in a string and constructs a new string with all the uppercase characters converted to lowercase and all the lowercase characters converted to uppercase. Let's write the code for this function — Example Following is the code — const str = 'The Case OF tHis StrinG Will Be FLiPped'; const isUpperCase = char => char.charCodeAt(0) >= 65 && char.charCodeAt(0) char.charCodeAt(0) >= 97 && char.charCodeAt(0) { let newStr = ''; const margin = 32; ...
Read MoreUIWebView HTML5 Canvas & Retina Display
When working with HTML5 Canvas on retina displays in UIWebView, images may appear blurry due to pixel density differences. Here's how to properly handle retina displays for crisp canvas rendering. The Retina Display Problem Retina displays have higher pixel density (devicePixelRatio > 1), but Canvas elements default to standard resolution, causing blurry images and drawings. Solution: Scale Canvas for Retina The key is to scale the canvas context and adjust its internal dimensions to match the device's pixel ratio: var canvas = document.getElementById('myCanvas'); var context = canvas.getContext('2d'); var width = 300; ...
Read MoreFinding duplicate "words" in a string - JavaScript
We need to write a JavaScript function that takes a string and returns only the words that appear more than once in the original string. For example, if the input string is: const str = "big black bug bit a big black dog on his big black nose"; Then the output should be: "big black" Solution Using indexOf() and lastIndexOf() We can identify duplicates by comparing the first and last occurrence positions of each word: const str = "big black bug bit a big black dog on his ...
Read MoreThe dragLeave event fires before drop for HTML5 drag and drop events
In HTML5 drag and drop operations, the dragLeave event can sometimes fire unexpectedly before the drop event, causing visual inconsistencies or premature cleanup of drop zone styling. This occurs due to event bubbling and the complex nature of drag operations. Understanding the Problem The dragLeave event fires when the dragged element leaves the boundaries of a drop target. However, it can also fire when moving between child elements within the same drop zone, causing unwanted behavior. Basic Drag and Drop Setup Here's a complete working example that demonstrates the issue and solution: ...
Read MoreFinding roots of a quadratic equation – JavaScript
A quadratic equation has the form ax² + bx + c = 0, where a, b, and c are coefficients. To find the roots, we use the quadratic formula and check if the discriminant is non-negative for real roots. Quadratic Formula The quadratic formula is: x = (-b ± √(b² - 4ac)) / (2a) The discriminant (b² - 4ac) determines the nature of roots: If discriminant > 0: Two distinct real roots If discriminant = 0: One repeated real root If discriminant < 0: No real roots (complex roots) Example ...
Read MoreCan Google Analytics track interactions in an offline HTML5 app?
Google Analytics is a freemium analytic tool that provides detailed statistics of web traffic. It is used by more than 60% of website owners. Analytics tools offer insights into website performance, visitor behavior, and data flow. These tools are inexpensive and easy to use, sometimes even free. Yes, Google Analytics can track interactions in offline HTML5 apps, but with specific limitations and considerations. How Offline Tracking Works When an HTML5 application goes offline, Google Analytics stores tracking events in the browser's local storage or SQLite database. After storing these events, it waits until the user comes back ...
Read MoreMove an HTML div in a curved path
To move an HTML div in a curved path, you can use CSS animations, JavaScript, or HTML5 Canvas. JavaScript provides the most flexibility and browser compatibility for complex curved animations. CSS Transitions - Simple curved paths using cubic-bezier JavaScript (jQuery) - Custom curved animations with precise control HTML5 Canvas - Complex curved paths with mathematical precision We'll focus on JavaScript solutions using jQuery's animate() method and modern CSS transforms. jQuery animate() Method The animate() method performs custom animations by changing CSS properties over time. ...
Read MoreOverride HTML5 validation
HTML5 form validation can be overridden using JavaScript by removing validation attributes or preventing the default validation behavior. This is useful when you need custom validation logic or want to bypass built-in constraints. Method 1: Using removeAttribute() The removeAttribute() method removes validation attributes like required from form elements: First Name: Remove Required ...
Read MoreNearest power 2 of a number - JavaScript
We need to write a JavaScript function that takes a number and returns the nearest power of 2. A power of 2 is any number that can be expressed as 2n where n is a whole number (1, 2, 4, 8, 16, 32, 64, 128, 256, etc.). For example, if the input is 365, the output should be 256 because 256 (28) is closer to 365 than the next power of 2, which is 512 (29). Algorithm Explanation The algorithm works by: Starting with base = 1 (20) Doubling the base until it exceeds the input ...
Read More