Found 6710 Articles for Javascript

How to disable mouse event on certain elements using JavaScript?

AmitDiwan
Updated on 17-Jul-2020 08:38:57

4K+ Views

Following is the code for disabling mouse event on certain elements using JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px;       font-weight: 500;       color: rebeccapurple;    }    .size {       font-size: 30px;    } Disable Mouse events using JavaScript This is some text inside a div DISABLE ENABLE Click on the above button to enable or disable mouse events    let resEle ... Read More

JavaScript program to access browsing history

AmitDiwan
Updated on 23-Dec-2024 11:17:25

675 Views

In this article, we will learn to access browsing history using Javascript. In web development, accessing a user’s browsing history can improve user experience and provide personalized content. However, due to privacy concerns and security reasons, modern web browsers limit the amount of browsing history accessible via JavaScript.  What is Browsing History? Browsing history refers to the list of web pages that a user has visited over a while. Browsers typically store this data locally, allowing users to navigate back and forth through the pages they’ve visited. The window.history Object In JavaScript, the window.history object allows interaction with the browser’s ... Read More

Explain Enumerated Types in JavaScript.

AmitDiwan
Updated on 17-Jul-2020 08:23:14

158 Views

JavaScript doesn’t support Enums out of the box. The only way to have enums in javaScript is to implement them using objects.Following is the code showing enumerated types in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px;       font-weight: 500;       color: rebeccapurple;    } Enumerated Types in JavaScript CLICK HERE Click on the above button to get the color values    let resEle = document.querySelector(".result");   ... Read More

How to embed JavaScript in HTML file?

AmitDiwan
Updated on 17-Jul-2020 08:20:18

520 Views

Following is the code to embed JavaScript in html file −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px;       font-weight: 500;       color: rebeccapurple;    } Embed javascript in html file    let resEle = document.querySelector(".result");    resEle.innerHTML += "Inline javaScript loaded" + ""; script.jsresEle.innerHTML += 'External JavaScript loaded ';OutputThe above code will produce the following output −

Explain shorthand functions in JavaScript?

AmitDiwan
Updated on 17-Jul-2020 08:16:46

1K+ Views

The arrow functions also known as shorthand functions were introduced in ES2015 and allows us to write function in a shorter way. They don’t have their own binding to this and get the this from the surrounding context.Following is the code showing shorthand functions in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px;       font-weight: 500;       color: rebeccapurple;    } Shorthand function in JavaScript CLICK HERE Click ... Read More

How to create a URL object using JavaScript?

AmitDiwan
Updated on 17-Jul-2020 08:12:47

506 Views

Following is the code to create a URL object using JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px;       font-weight: 500;       color: rebeccapurple;    } Url object in JavaScript CLICK HERE Click on the above button to create and display a url object    let resEle = document.querySelector(".result");    let url = new URL("https://google.com/image=23&size=440px");    document.querySelector(".Btn").addEventListener("click", () => {       resEle.innerHTML += "url protocol = " + url.protocol + "";       resEle.innerHTML += "url host = " + url.host + "";       resEle.innerHTML += "url.pathname = " + url.pathname + "";    }); OutputThe above code will produce the following output −On clicking the ‘CLICK HERE’ button −

Flattening multi-dimensional arrays in JavaScript

AmitDiwan
Updated on 17-Jul-2020 08:15:57

379 Views

Following is the code for flattening multi-dimensional arrays in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result,    .sample {       font-size: 20px;       font-weight: 500;    } Flattening multi-dimensional arrays in JavaScript [1,2,3,[4,5],[6,[7,8]]] After flat : CLICK HERE Click on the above button to flat the above array by depth 2    let resEle = document.querySelector(".result");    let sampleEle = document.querySelector(".sample");    let arr = [1, 2, 3, [4, 5], [6, [7, 8]]];    document.querySelector(".Btn").addEventListener("click", () => {       let store = arr.flat(2);       store.forEach((item, index) => {          resEle.innerHTML += index + " : " + item + "";       });    }); OutputOn clicking the ‘CLICK HERE’ button

File and FileReader in JavaScript?

AmitDiwan
Updated on 17-Jul-2020 08:05:46

343 Views

Following is the code showing file and fileReader in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result, .sample {       font-size: 18px;       font-weight: 500;       color: rebeccapurple;    }    .result {       color: red;    } File and FileReader in JavaScript Click on the above button to display file and its details    let resEle = document.querySelector(".result");    let sampleEle = document.querySelector(".sample");    function ... Read More

How to access JavaScript properties?

AmitDiwan
Updated on 17-Jul-2020 07:54:32

273 Views

There are three ways to access JavaScript properties −Using dot property access: object.propertyUsing square brackets notation: object[‘property’]Using object destructuring: let {property} = objectFollowing is the code for accessing JavaScript object properties −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result,    .sample {       font-size: 18px;       font-weight: 500;       color: blueviolet;    }    .sample {       color: red;    } Access JavaScript object properties {a:22, b:44} Access Click on the ... Read More

How to convert an Image to blob using JavaScript?

AmitDiwan
Updated on 17-Jul-2020 07:57:11

15K+ Views

Following is the code to convert an image to blob using JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px;       font-weight: 500;       color: rebeccapurple;    } Convert an Image to blob using JavaScript Convert Click on the above button to convert the above image to blob    let BtnEle = document.querySelector(".Btn");    let resEle = gdocument.querySelector(".result");    BtnEle.addEventListener("click", () => {     ... Read More

Advertisements