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
Front End Technology Articles
Page 335 of 652
How to test if a JavaScript cookie has expired?
To test if a JavaScript cookie has expired, you need to check if the cookie exists or returns null. When a cookie expires, the browser automatically removes it, so attempting to access it will return null or undefined. Using document.cookie (Vanilla JavaScript) The most straightforward approach is to create a helper function that checks if a cookie exists: function getCookie(name) { const cookies = document.cookie.split(';'); for (let cookie of cookies) { const [cookieName, cookieValue] = cookie.trim().split('='); ...
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 I can show JavaScript alert box in the middle of the screen?
The native JavaScript alert() box cannot be repositioned as its styling and position are controlled by the browser. To show an alert box in the center of the screen, you need to create a custom alert dialog using HTML, CSS, and JavaScript. Why Native alert() Can't Be Centered The built-in alert() function displays a browser-controlled modal that appears at a fixed position determined by the browser, typically near the top of the viewport. This position cannot be customized through CSS or JavaScript. Creating a Custom Centered Alert Box Here's how to create a custom alert that ...
Read MoreHow to customize the position of an alert box using JavaScript?
To customize the position of an alert box, you need to create a custom alert since the native JavaScript alert() function cannot be positioned. We can build a custom alert box using HTML, CSS, and JavaScript, then control its position using CSS properties like top and left. Creating a Custom Alert Box The native alert() box position is controlled by the browser and cannot be customized. Instead, we create a custom modal dialog that mimics an alert box behavior. Example: Custom Positioned Alert Here's how to create a custom alert box with customizable positioning: ...
Read MoreHow to center the JavaScript alert message box?
In this tutorial, we will learn to center the JavaScript alert box. In JavaScript, an alert box is useful to show users some message, information, warning, success, etc. Let's understand it by real-world example when you open any website on the web browser and start to authenticate by entering your username and password. When you click the submit button, it gives a message in an alert box like the password should be 8 or more characters, or sign in successfully. Users can create the alert box using JavaScript's alert() method. Unfortunately, the default alert box doesn't allow us to ...
Read MoreWhat is the difference between void, eval, and the Function constructor in JavaScript?
JavaScript provides three distinct features for executing and manipulating code: void, eval(), and the Function constructor. Each serves different purposes and has unique characteristics. The void Operator The void operator evaluates an expression and always returns undefined. It's commonly used to prevent unwanted return values or create undefined values explicitly. Syntax void expression void(expression) Example // Basic void usage console.log(void 0); ...
Read MoreWhy does the JavaScript void statement evaluate an expression?
The JavaScript void operator evaluates an expression and always returns undefined, regardless of what the expression returns. This is useful for preventing unwanted side effects in web pages. What is the void Operator? The void operator takes any expression, evaluates it, and returns undefined. It's commonly used in links to prevent navigation while still executing JavaScript code. Syntax void expression void(expression) Example: Using void(0) in Links The most common use case is void(0) in hyperlinks to prevent page navigation: Understanding JavaScript void(0) ...
Read MoreHow can I stop a video with JavaScript in Youtube?
In this tutorial, we will learn to stop a video with JavaScript on YouTube. Using the 'iframe' HTML element, we can easily embed the YouTube videos on our application. It is a video player in HTML 5 and has many attributes that users can use according to their needs. In some cases, it happens that you want to create a custom pause or stop button for the embedded YouTube video. Customized buttons are always pretty rather than default ones, making UI pretty. So, we will learn two different methods to create the custom stop button for the YouTube ...
Read MoreHow to create and apply CSS to JavaScript Alert box?
The standard alert box in JavaScript does not provide the option to apply CSS. To style your alert box, you need to create a custom one first. The custom alert box will be created using jQuery and styles will be applied to CSS. Why Custom Alert Boxes? JavaScript's built-in alert() function creates browser-native dialogs that cannot be styled. Custom alert boxes give you complete control over appearance, animations, and user experience. Example You can try to run the following code to learn how to create and apply CSS to alert box: ...
Read MoreHow to check if a variable is an integer in JavaScript?
In this tutorial, we will learn to check if a variable is an integer in JavaScript. Before we solve the problem, we must have a problem. We can ask ourselves, "why do we need to check if the variable is an integer?". Let's understand the answer using a single example. Suppose, we are taking the value from the user using the input text box. It returns the values in the string format, and now think that we are adding values. Will we get the correct result? Obviously, not. So, in such cases, we need to check if the variable is ...
Read More