Javascript Articles

Page 365 of 534

How to choose between `window.URL.createObjectURL()` and `window.webkitURL.createObjectURL()` based on browser?

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

When working with file blobs in JavaScript, different browsers may support different implementations of createObjectURL(). Modern browsers use window.URL.createObjectURL(), while older WebKit browsers used window.webkitURL.createObjectURL(). Browser Compatibility Issue The webkitURL prefix was used in older versions of Chrome and Safari, while modern browsers have standardized on URL.createObjectURL(). Creating a Cross-Browser Wrapper Function To handle both cases, create a wrapper function that checks for browser support: function createObjectURL(file) { if (window.URL && window.URL.createObjectURL) { return window.URL.createObjectURL(file); } else if (window.webkitURL) { ...

Read More

Convert buffer to readable string in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 783 Views

In Node.js, buffers store binary data and need to be converted to strings for readability. The toString() method with encoding parameters handles this conversion. What is a Buffer? A Buffer is a Node.js object that represents a fixed-size chunk of memory allocated outside the JavaScript heap. It's used to handle binary data directly. Basic Buffer to String Conversion Use the toString() method with the appropriate encoding. UTF-8 is the most common encoding for text data. // Create a buffer from string var actualBufferObject = Buffer.from('[John Smith]', 'utf8'); console.log("The actual buffer object:"); console.log(JSON.stringify(actualBufferObject)); // ...

Read More

How to listen to Keydown-Events in a KineticJS-managed HTML5-Canvas?

Rishi Rathor
Rishi Rathor
Updated on 15-Mar-2026 171 Views

To listen to keydown events in a KineticJS-managed HTML5 canvas, you need to make the canvas focusable and attach event listeners. KineticJS canvases don't receive keyboard events by default since they're not focusable elements. Making the Canvas Focusable First, get the canvas element and make it focusable by setting the tabindex attribute: // Create KineticJS stage and layer ...

Read More

Drawing lines with continuously varying line width on HTML canvas

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

Drawing lines with continuously varying line width on HTML canvas creates smooth, dynamic visual effects. This technique uses quadratic curves and gradually increases the line width to create flowing, organic-looking lines. Understanding the Approach The technique involves generating a series of points along a curved path and drawing segments between them with incrementally increasing line widths. Each segment uses quadraticCurveTo() to create smooth curves rather than sharp angles. Complete Example Variable Line Width Canvas ...

Read More

Alternatives to HTML5 iframe srcdoc?

George John
George John
Updated on 15-Mar-2026 635 Views

The HTML tag is used to create an inline frame. While the srcdoc attribute allows embedding HTML content directly, several alternatives exist for dynamically setting iframe content. Understanding iframe srcdoc The srcdoc attribute specifies HTML content to display inside an iframe without requiring an external URL. iframe srcdoc Example Alternative 1: Using contentWindow.document Access the iframe's document object directly to write content programmatically. contentWindow Alternative ...

Read More

JavaScript outsider function call and return the result

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 219 Views

In JavaScript, you can call functions from outside their defining scope by using the return keyword to return inner functions. This creates closures that maintain access to outer variables. Syntax function outerFunction() { // Outer variables var outerVar = value; // Inner function var innerFunction = function() { // Can access outerVar return result; } ...

Read More

Can a user disable HTML5 sessionStorage?

Vrundesha Joshi
Vrundesha Joshi
Updated on 15-Mar-2026 2K+ Views

Yes, users can disable HTML5 sessionStorage in their browsers. When disabled, attempts to use sessionStorage will either throw errors or fail silently, depending on the browser implementation. How Users Can Disable sessionStorage Different browsers provide various methods to disable DOM storage, which affects both localStorage and sessionStorage: Firefox Type "about:config" in the address bar and press Enter Search for "dom.storage.enabled" Right-click and toggle to "false" to disable DOM Storage Chrome Go to Settings → Privacy and security → Site Settings Click "Cookies and site data" Select "Block third-party cookies" or "Block all cookies" ...

Read More

How Do I Find the Largest Number in a 3D JavaScript Array?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 216 Views

To find the largest number in a 3D JavaScript array, we can use flat(Infinity) to flatten all nested levels, then apply Math.max() to find the maximum value. The Problem 3D arrays contain multiple levels of nested arrays, making it difficult to directly compare all numbers. We need to flatten the structure first. var theValuesIn3DArray = [75, [18, 89], [56, [97], [99]]]; Using flat() with Math.max() The flat(Infinity) method flattens all nested levels, and the spread operator ... passes individual elements to Math.max(). var theValuesIn3DArray = [75, [18, 89], [56, [97], [99]]]; ...

Read More

How to take a snapshot of HTML5-JavaScript based video player?

Ankith Reddy
Ankith Reddy
Updated on 15-Mar-2026 876 Views

You can capture a still frame from an HTML5 video player by drawing the current video frame onto a canvas element. This technique is useful for creating thumbnails, implementing pause screens, or saving video snapshots. How It Works The process involves using the drawImage() method to copy the current video frame to a canvas. The canvas acts as a snapshot buffer that can be manipulated or saved. Example Your ...

Read More

Checking for co-prime numbers - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 518 Views

Two numbers are said to be co-primes if there exists no common prime factor amongst them (1 is not a prime number). For example: 4 and 5 are co-primes 9 and 14 are co-primes 18 and 35 are co-primes 21 and 57 are not co-prime because they have 3 as the common prime factor We are required to write a function that takes in two numbers and returns true if they are co-primes otherwise returns false. Understanding Co-prime Numbers Two numbers are co-prime if their greatest common divisor (GCD) is 1. This means ...

Read More
Showing 3641–3650 of 5,340 articles
« Prev 1 363 364 365 366 367 534 Next »
Advertisements