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 379 of 534
How to load an HTML file into the canvas?
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 MoreFinding persistence of number in JavaScript
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 MoreXMLHttpRequest for Video Tag?
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 MoreJS Geolocation but without prompting possible?
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 MoreExpressing numbers in expanded form - JavaScript
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 MorejQuery Mobile: Sending data from one page to the another
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 MoreMaking an image scale mouse over on HTM5
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 MoreChecking if two arrays can form a sequence - JavaScript
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 MoreDataTransfer object in HTML5
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 MoreWhat are the DataTransfer object attributes?
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