Javascript Articles

Page 372 of 534

How to keep audio playing while navigating through pages?

Samual Sam
Samual Sam
Updated on 15-Mar-2026 1K+ Views

To keep audio playing while navigating through pages, you need to prevent full page reloads that would interrupt playback. Here are the main approaches: Method 1: Using AJAX with History API Load new content dynamically without refreshing the page using AJAX combined with the History API's pushState() method. Continuous Audio Example ...

Read More

Chrome and HTML5 GeoLocation denial callback

Krantik Chavan
Krantik Chavan
Updated on 15-Mar-2026 228 Views

When using HTML5 Geolocation API in Chrome, users can deny location access or the request can timeout. Here's how to handle these scenarios properly. The Challenge Chrome's geolocation behavior can be unpredictable when users deny permission or when requests timeout. The callbacks might not always fire as expected, requiring additional timeout handling. Basic Error Handling The geolocation API accepts success and error callbacks: Geolocation Example function successCallback(position) { ...

Read More

Finding area of triangle in JavaScript using Heron's formula

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 952 Views

We are given the lengths of three sides of a triangle and we are required to write a function that returns the area of the triangle using the length of its sides. Heron's Formula We can calculate the area of a triangle if we know the lengths of all three sides, using Heron's formula: Step 1 − Calculate "s" (half of the triangle's perimeter): s = (a + b + c) / 2 Step 2 − Then calculate the Area using Heron's formula: A = √(s(s-a)(s-b)(s-c)) Syntax ...

Read More

Using client side XSLT transformations in HTML5

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 294 Views

Client-side XSLT transformations allow you to convert XML data into HTML directly in the browser using JavaScript's XSLTProcessor API. This is useful for displaying XML data in a formatted way without server-side processing. Browser Support The XSLTProcessor API is supported by most modern browsers, including Chrome, Firefox, Safari, and Edge. Android 4.0+ and iOS 2.0+ also support XSLT transformations. Basic Syntax const processor = new XSLTProcessor(); processor.importStylesheet(xslDocument); const result = processor.transformToFragment(xmlDocument, document); Complete Example Here's a working example that transforms XML book data into HTML: ...

Read More

Split string into groups - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 317 Views

Given a string that consists of alphabets, numbers, and special characters, we need to split it into three separate strings based on character type. We'll create three strings where: S1 contains all alphabets from the original string S2 contains all numbers from the original string S3 contains all special characters from the original string The characters in each resulting string maintain the same order as they appear in the input string. Example Implementation const str = "Th!s String C0nt@1ns d1fferent ch@ract5rs"; const ...

Read More

HTML5 validity of nested tables

Nishtha Thakur
Nishtha Thakur
Updated on 15-Mar-2026 216 Views

The HTML5 validator considers nested tables valid when properly structured. Here's how to create valid nested table markup in HTML5. Valid Nested Table Structure A nested table must be placed inside a or element of the parent table. The validator considers the following structure valid: Nested Table Example ...

Read More

Swap kth element of array - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 670 Views

We are required to write a JavaScript function that accepts an array of Numbers and a number, say k (k must be less than or equal to the length of array). And our function should replace the kth element from the beginning with the kth element from the end of the array. Understanding the Problem When we say "kth element from beginning" and "kth element from end", we need to understand the positioning: kth element from beginning: index = k - 1 kth element from end: index = array.length - k Example ...

Read More

Cross origin HTML does not load in Google Chrome

Samual Sam
Samual Sam
Updated on 15-Mar-2026 245 Views

When loading HTML content from a different origin in Google Chrome, you may encounter CORS (Cross-Origin Resource Sharing) errors. This happens because browsers enforce the same-origin policy for security reasons. Common Cross-Origin Issues Cross-origin problems typically occur when: Loading resources from different domains Using different protocols (HTTP vs HTTPS) Different ports on the same domain Missing proper CORS headers Solution 1: Setting crossorigin for Video Elements For video elements that fail to load cross-origin content, set the crossorigin attribute to "anonymous": Cross-Origin Video ...

Read More

Squared sum of n odd numbers - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 333 Views

We are required to write a JavaScript function that takes in a Number, say n, and finds the sum of the square of first n odd natural Numbers. For example, if the input number is 3, we need to find the first 3 odd numbers (1, 3, 5) and calculate the sum of their squares: 1² + 3² + 5² = 1 + 9 + 25 = 35 Understanding the Pattern The first n odd natural numbers follow the pattern: 1, 3, 5, 7, 9... The formula for the i-th odd number is (2 * i) - 1. Example const num = 3; const squaredSum = num => { let sum = 0; for(let i = 1; i

Read More

Unable to take a photo from webcam using HTML5 and on the first page load

Lakshmi Srinivas
Lakshmi Srinivas
Updated on 15-Mar-2026 289 Views

When taking photos from webcam using HTML5, you may encounter issues on first page load. This typically happens due to improper initialization or missing user permissions. Here's how to properly implement webcam photo capture: HTML Structure Take Photo Declare Variables var streaming = false, video = document.querySelector('#video'), canvas = document.querySelector('#canvas'), photo = document.querySelector('#photo'), startbutton = document.querySelector('#startbutton'), width = 320, height = 0; Initialize Camera ...

Read More
Showing 3711–3720 of 5,340 articles
« Prev 1 370 371 372 373 374 534 Next »
Advertisements