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
Articles by Nishtha Thakur
Page 2 of 40
Execute a script when the document is about to be unloaded in HTML?
The onbeforeunload event attribute in HTML fires when the document is about to be unloaded, such as when a user closes the browser tab, navigates away from the page, or refreshes it. This event is commonly used to warn users about unsaved changes or to perform cleanup operations before the page is destroyed. Syntax Following is the syntax for the onbeforeunload event attribute − The event handler function can return a string message that will be displayed in the browser's confirmation dialog. However, modern browsers may show their own generic message instead of ...
Read MoreHTML5 validity of nested tables
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 MoreFrame by frame animation in HTML5 with canvas
Frame by frame animation in HTML5 canvas creates smooth animations by displaying a sequence of images in rapid succession, similar to traditional flipbook animation. Basic Frame Animation Structure The core concept involves cycling through numbered image files and drawing them onto the canvas at regular intervals using setInterval(). Complete Example Frame Animation var canvas = document.getElementById('animationCanvas'); ...
Read MoreHow to get a key/value data set from a HTML form?
To get key/value data from an HTML form, you can use several approaches including jQuery's serializeArray(), vanilla JavaScript with FormData, or manual field extraction. HTML Form Example Let's start with a sample HTML form: Using jQuery serializeArray() jQuery's serializeArray() returns an array of objects with name and value properties: // Using jQuery serializeArray() var data = $('#form1').serializeArray(); console.log(data); // Convert ...
Read MoreApply gravity between two or more objects in HTML5 Canvas
To apply gravity between two or more objects in HTML5 Canvas, you need to calculate the gravitational force between each pair of objects and update their velocities accordingly. Gravitational Force Formula The gravitational force between two objects is calculated using Newton's law of universal gravitation. In our simplified 2D canvas implementation, we use: F = G * (m1 * m2) / r² Where F is the force, G is the gravitational constant, m1 and m2 are the masses, and r is the distance between objects. Basic Gravity Calculation Here's how to calculate ...
Read MoreHow I can set the width and height of a JavaScript alert box?
JavaScript's native alert() function creates a browser-controlled dialog box whose size cannot be customized. To set the width and height of an alert box, you need to create a custom alert dialog using HTML, CSS, and JavaScript. Why Native alert() Cannot Be Resized The browser's built-in alert() function creates a modal dialog with fixed dimensions determined by the browser and operating system. These native alerts cannot be styled or resized using CSS or JavaScript. Creating a Custom Alert Box Here's how to create a customizable alert box with specific width and height dimensions using jQuery: ...
Read MoreHow to create multi-column layout in HTML5 using tables?
Design your webpage to display content across multiple columns using HTML tables. This approach allows you to create structured layouts with a main content area in the center, navigation menu on the left, and additional content like advertisements on the right. Basic Three-Column Layout Structure Tables provide a simple way to create multi-column layouts by using table rows () and table data cells (). Each cell acts as a separate column with customizable width and styling. Example Three Column HTML Layout ...
Read MoreTranslating HTML5 canvas
Use the translate() method to move the HTML5 canvas coordinate system. The translate(x, y) method shifts the canvas origin to a different point in the grid. The x parameter moves the canvas left (negative) or right (positive), and y moves it up (negative) or down (positive). Syntax context.translate(x, y); Parameters Parameter Description x Horizontal distance to ...
Read MoreHow to detect a particular feature through JavaScript with HTML
Feature detection in JavaScript allows you to check if a browser supports specific HTML5 features before using them. This ensures your web application works across different browsers and devices. Using Native JavaScript Feature Detection You can detect features using native JavaScript without external libraries: // Detect audio support function supportsAudio() { return !!document.createElement('audio').canPlayType; } // Detect video support function supportsVideo() { return !!document.createElement('video').canPlayType; } // Detect canvas support function supportsCanvas() { var canvas = document.createElement('canvas'); return !!(canvas.getContext && ...
Read MoreWrite a Regular Expression to remove all special characters from a JavaScript String?
To remove all special characters from a JavaScript string, you can use regular expressions with the replace() method. The most common approach is using the pattern /[^\w\s]/g which matches any character that is not a word character or whitespace. Syntax string.replace(/[^\w\s]/g, '') Regular Expression Breakdown The pattern /[^\w\s]/g works as follows: [^...] - Negated character class (matches anything NOT in the brackets) \w - Word characters (a-z, A-Z, 0-9, _) \s - Whitespace characters (spaces, tabs, newlines) g - Global flag (replace all occurrences) Example: Basic Special Character Removal ...
Read More