Javascript Articles

Page 379 of 534

How to load an HTML file into the canvas?

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

Loading HTML content into a canvas requires converting HTML to an image format that canvas can display. The most effective approach uses SVG foreignObject to wrap HTML, then render it as an image. Method 1: Using SVG foreignObject The foreignObject element allows embedding HTML content within SVG, which can then be rendered on canvas. const canvas = document.getElementById('myCanvas'); const ctx = canvas.getContext('2d'); // HTML content wrapped in SVG foreignObject const htmlContent = ` Hello Canvas! ...

Read More

Finding persistence of number in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 424 Views

The additive persistence of a number is the count of times you must repeatedly sum its digits until you get a single digit. This is a common programming problem that demonstrates recursion and digit manipulation. Understanding Additive Persistence For any positive integer, we replace it with the sum of its digits repeatedly until we reach a single digit (0-9). The number of iterations required is the additive persistence. For example, with 1679583: 1679583 → 1+6+7+9+5+8+3 = 39 (Pass 1) 39 → 3+9 = 12 ...

Read More

XMLHttpRequest for Video Tag?

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

XMLHttpRequest can be used to fetch video data as a blob and display it in HTML5 video elements. This approach is useful for loading video content programmatically or handling binary video data. Basic XMLHttpRequest with Blob First, let's understand how to send binary data using XMLHttpRequest with a Blob object: var xhr = new XMLHttpRequest(); xhr.open("POST", "/upload", true); xhr.onload = function (event) { console.log("Upload complete"); }; // Create a blob with text data var blob = new Blob(['demo content'], {type: 'text/plain'}); xhr.send(blob); Loading Video with XMLHttpRequest ...

Read More

JS Geolocation but without prompting possible?

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

No, you cannot access geolocation data without prompting the user. This is a mandatory security feature designed to protect user privacy. Location Permission Allow example.com to access your location? Block Allow ...

Read More

Expressing numbers in expanded form - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 897 Views

Suppose we are given a number 124 and are required to write a function that takes this number as input and returns its expanded form as a string. The expanded form of 124 is − '100+20+4' How It Works The algorithm converts each digit to its place value by multiplying it with the appropriate power of 10, then joins non-zero values with '+' signs. Example Following is the code − const num = 125; const expandedForm = num => { const numStr = String(num); ...

Read More

jQuery Mobile: Sending data from one page to the another

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

jQuery Mobile provides several methods to pass data between pages. The most common approaches include URL parameters, localStorage, and sessionStorage. Method 1: Using URL Parameters Pass data through the URL query string when navigating between pages. HTML Link with Parameters Go to New Page JavaScript to Extract Parameters $(document).on("pageinit", "#new", function(event) { // Get URL parameters var url = $(this).data("url"); if (url) { ...

Read More

Making an image scale mouse over on HTM5

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

To make an image scale on mouse over in HTML5, you can use CSS transforms or Canvas API. Here we'll show both approaches for creating smooth scaling effects. Method 1: Using CSS Transform (Recommended) The simplest approach uses CSS transform: scale() with :hover pseudo-class: .scalable-image { width: 200px; height: 200px; ...

Read More

Checking if two arrays can form a sequence - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 249 Views

We are required to write a JavaScript function that takes in two arrays of numbers. And the function should return true if the two arrays upon combining and shuffling can form a consecutive sequence, false otherwise. For example − If the arrays are − const arr1 = [4, 6, 2, 9, 3]; const arr2 = [1, 5, 8, 7]; Then the output should be true because when combined and sorted, they form: [1, 2, 3, 4, 5, 6, 7, 8, 9] which is a consecutive sequence. Example Following is the code − ...

Read More

DataTransfer object in HTML5

Jennifer Nicholas
Jennifer Nicholas
Updated on 15-Mar-2026 446 Views

The DataTransfer object is a key component of HTML5 drag and drop functionality. It provides methods to store and retrieve data during drag operations and control the visual feedback shown to users. Accessing the DataTransfer Object All drag and drop event handlers receive an Event object with a readonly dataTransfer property that returns the DataTransfer object associated with the event: function dragStartHandler(event) { let dataTransfer = event.dataTransfer; // Use dataTransfer methods here } Key DataTransfer Methods The DataTransfer object provides several important methods: ...

Read More

What are the DataTransfer object attributes?

Nitya Raut
Nitya Raut
Updated on 15-Mar-2026 585 Views

The DataTransfer object holds data about the drag and drop operation. This data can be retrieved and set using various attributes and methods associated with the DataTransfer object. The DataTransfer object is automatically created by the browser during drag and drop operations and is available through the event object in drag event handlers. DataTransfer Attributes and Methods Property/Method ...

Read More
Showing 3781–3790 of 5,340 articles
« Prev 1 377 378 379 380 381 534 Next »
Advertisements