Found 6685 Articles for Javascript

Why split the <script> tag when writing it with document.write()?

Shubham Vora
Updated on 07-Dec-2022 11:12:25

994 Views

In this tutorial, we will learn why to split the tag when writing it with the document.write(). The script tag in HTML is added to execute JavaScript code on the webpage. The JavaScript programs must be enclosed with the script tag to execute. There are many methods in JavaScript that add HTML content to the page, like the document.write() method. The document.write() method is used to delete all the content from the HTML tag or the document and add the content specified in this method to the page. Because of performance degradation and errors in certain conditions, this method ... Read More

How to stop refreshing the page on submit in JavaScript?

Shubham Vora
Updated on 02-Sep-2023 11:31:26

76K+ Views

In this tutorial, we shall learn to stop form refreshing the page on submitting in JavaScript. Let’s cover the methods to accomplish this objective. Using event.preventDefault() to stop page refresh on form submit In this section, we will see how to use event.preventDefault() to stop page refresh on form submission. The event.preventDefault() restricts the default page refresh behavior of the form during form submission. Users can follow the syntax below to try this method. Syntax The syntax defines the form. //Get form element var form=document.getElementById("formId"); function submitForm(event){ ... Read More

Is it possible to write data to file using only JavaScript?

Shubham Vora
Updated on 06-Dec-2022 12:37:50

356 Views

In this tutorial, we will learn if it is possible to write data to files using only JavaScript. JavaScript has a library named fs (short form of File-System) that manages all writing operations. It is a JavaScript program (fs.js) with functions for writing operations. Utilize functions to write text to system files by importing the fs module into the program. For example, the writeFile() function will erase all old data from a file and create a new one with the specified name if there isn’t already one. It is mainly used for writing operations. The File-System module is a handy ... Read More

How to Access the Correct “this” Inside a Callback?

Shubham Vora
Updated on 06-Dec-2022 12:19:17

464 Views

In this tutorial, we will learn about how to Access the Correct “this” inside a callback. “this” keyword Each function contains a keyword called this, also known as “the context, ” whose value is determined by how the function was called and not by how, when, or where it was defined. Unlike other variables, it is unaffected by lexical scopes. Compared to other languages, JavaScript acts a little differently when a function’s “this” keyword is used. Between strict mode and non-strict mode, there are several further changes. How a function is called most often determines the value of “this” (runtime ... Read More

How to capture HTML Canvas as gif/jpg/png/pdf with JavaScript?

AmitDiwan
Updated on 06-Dec-2022 11:18:06

3K+ Views

We can Use the canvas.toDataURL() to capture HTML canvas as different file formats, such as gif, png, jpg, webp, etc. Capture HTML Canvas as png Example Herein, after using canvas.DataURL(), set the type to image/png to allow saving the image as PNG − window.onload = function() { var canvas = document.getElementById("myCanvas"); var context = canvas.getContext("2d"); context.fillStyle ... Read More

How do find out all elements that match a specific condition in JavaScript?

Aman Kumar
Updated on 06-Dec-2022 06:08:13

974 Views

We can find the specific condition with the help of the _.whare() function. The _.where() belongs to underscore.js a javascript library that provides versatile functions. The _.where() is a function used to find the specific element according to the given conditions. Suppose you want to find all the user details of the class and then apply the _.where() function to the list of all the sections and pass the condition as the section name. So the name of all the users with the specific condition will be returned. Syntax _.where( list, [predicate], [context] ) The function accepts three-argument as ... Read More

What are decorators and how are they used in JavaScript?

Kalyan Mishra
Updated on 01-Dec-2022 12:21:51

889 Views

In this tutorial, you will learn about JavaScript decorators and get to know about their inner workings and uses. What are Decorators in JavaScript? The word decorator means combining a set of code or program with another or can be said as wrapping a function with another function to extends the functionality or working of the function. Decorator can also be called as decorator function. Developers have been using this decorator term in other languages like python, C# and now JavaScript has also introduced the decorator. Function decorators In JavaScript functions behaves like objects so they are also known as ... Read More

How to manipulate DOM using a service worker in JavaScript?

Kalyan Mishra
Updated on 01-Dec-2022 12:04:49

1K+ Views

In this tutorial, you will learn about JavaScript DOM manipulation using a service worker. DOM manipulation happens is when we change the structure and elements of the document object model(DOM). We can modify DOM by adding, removing, Changing, or modifying elements and their attributes. What is a Service worker? Service workers work like proxy servers between web browsers and the web server. It adds enhancement to the existing websites in case the user’s browser doesn’t support the service worker but he visits any website that uses the service worker then also no function gets affected. It acts between web applications, ... Read More

How to upload an image using HTML and JavaScript in Firebase?

Kalyan Mishra
Updated on 01-Dec-2022 12:03:26

6K+ Views

In this tutorial, you will learn about the procedure to upload images in firebase using HTML and JavaScript. Firebase − Firebase is a cloud-based storage platform that is a product of google which provides storage services that are used in various web and mobile application development. It provides NoSQL and real-time hosting of the database, authentication, notification, content, and many more services. Steps to upload an image using HTML and JavaScript in Firebase To connect firebase to the project, you should create a project on firebase here is the step-by-step procedure to create and activate the storage service to upload ... Read More

How to Create a Video and Audio Recorder with JavaScript MediaRecorder API?

Kalyan Mishra
Updated on 01-Dec-2022 11:59:32

4K+ Views

In this tutorial, you will learn how to create an audio and video recorder using JavaScript MediaRecorder API. So this can be done using WebRTC. What is WebRTC? WebRTC is a short form of Real-Time Communication. We can access and capture the Webcam and Microphone devices that are available there in the user device. We can access the user device’s Webcam and microphone using an ECMAScript object navigator.mediaDevices.getUserMedia(constraints). So, the getUserMedia function by default, seeks user permission to use your Webcam. This function returns a promise and once you click ok and give the consent, then the function ... Read More

Advertisements