Found 6710 Articles for Javascript

How to get the current URL with JavaScript?

radhakrishna
Updated on 20-Apr-2022 12:12:57

1K+ Views

The window.location object can be used to get the current URL.window.location.href property returns the href (URL) of the current page. We could also use window.location or location in place of window.location.href.We could also use document.documentURI and document.URL properties.document.documentURI returns the location of the document as a string.document.URL returns the URL of the document as a string.Let’s understand how to get the current URL with JavaScript using the above properties with the help of program examples.Example 1 − Using window.location.href property.In this example we use window.location.href to get the current URL. In below example you can try using window.location or location ... Read More

How to set multiple cookies in JavaScript?

mkotla
Updated on 16-Jun-2020 11:59:40

4K+ Views

With JavaScript, to set more than one cookie, set document.cookie more than once using the; separator.ExampleYou can try to run the following code to set multiple cookies −Live Demo                 var num=1;       function addCookie() {          document.cookie=num+"="+num;          num++;       }       function listCookies() {          var result = document.cookie;          document.getElementById("list").innerHTML=result;       }       function removeCookies() {          var res = document.cookie;          var multiple = res.split(";");          for(var i=0;i

How to create JavaScript objects using new operator?

Krantik Chavan
Updated on 16-Jun-2020 13:39:41

317 Views

The new keyword in JavaScript is the new operator, which creates an instance of a user-defined object type.ExampleYou can try to run the following code to create JavaScript objects using new operator −Live Demo                          var dept = new Object();          dept.employee = "Amit";          dept.department = "Technical";          dept.technology ="Java";          document.getElementById("test").innerHTML =          dept.employee + " is working on " + dept.technology + " technology.";           OutputAmit is working on Java technology.

How can I pop-up a print dialog box using JavaScript?

Amit Sharma
Updated on 17-Jun-2020 06:09:24

4K+ Views

To pop-up a print dialog box using JavaScript, use the print() method. With the dialog box, you can easily set the printing options like which printer to select for printing.This is the dialog box −ExampleYou can try to run the following code to learn how to print a page −Live Demo           Click to Print                function display() {             window.print();          }          

How to design a custom alert box using JavaScript?

Prince Varshney
Updated on 06-Dec-2022 09:23:10

12K+ Views

In this tutorial, we are going to create one custom alert box using JavaScript. The alert box signifies a box that appears with some message on it whenever you click a button and if we add some styling to the box and mould it according to our requirements then it will be a custom alert box. Approach to design custom alert box using JavaScript To create a custom alert box, we will use a jQuery library which is used to simplify the HTML DOM manipulation and it also provides us with better use of event handling and CSS animation with ... Read More

How to print a number with commas as thousands of separators in JavaScript?

Shubham Vora
Updated on 20-Oct-2022 07:44:47

8K+ Views

In this tutorial, we will look at a few ways to print a number with commas as thousands of separators in JavaScript and compare them to understand which one is suitable in a given context. Why do we do number formatting? In English, commas are used to separate numbers bigger than 999. Dot is the thousands separator in Germany. Sweden uses space. The separator is added after every three digits from the right. Let’s briefly introduce the methods. Using the toLocaleString() Method Here, the built-in locale string method localizes the number format based on the country. ... Read More

How to set named cookies in JavaScript?

vanithasree
Updated on 03-Oct-2019 07:29:46

580 Views

To set named cookie in JavaScript, run the following code. It sets a customer name in an input cookie.ExampleLive Demo                                                  Enter name:                    

Is there a way to print all methods of an object in JavaScript?

Shubham Vora
Updated on 31-Oct-2022 11:12:59

1K+ Views

In this tutorial, we will learn how to print all methods of an object in JavaScript. An object's property with a function declaration is known as a JavaScript method. Methods are represented as object attributes and functions. We refer to actions carried out on objects as JavaScript methods. It is also possible to call the objects without using parentheses. This is a reference to the method's owner object. The method manipulates data that is part of a Class. The Object that was called into a method is implicitly passed. A function connected to an object attribute is called a method. ... Read More

What is cross-browser window resize events in JavaScript?

seetha
Updated on 16-Jun-2020 12:05:49

271 Views

For window resize event in JavaScript, use addEventListener(). The following code will give you the size of the current window −ExampleLive Demo                    div {             margin-top: 10px;             padding: 10px;             background-color: #1E9E5D;             width: 50%;          } span {             font-size: 50px;          }                                 window.addEventListener('resize', display);             function display() {                document.querySelector('.width').innerText = document.documentElement.clientWidth;                document.querySelector('.height').innerText = document.documentElement.clientHeight;             }             display();                                Width=          Height=          

How to set text font family in HTML?

Samual Sam
Updated on 31-Oct-2023 03:43:24

28K+ Views

To change the text font family in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML tag, with the CSS property font-family. HTML5 do not support the tag, so the CSS style is used to add font size.Just keep in mind, the usage of style attribute overrides any style set globally. It will override any style set in the HTML tag or external style sheet.ExampleYou can try to run the following code to change the text font family in an HTML pageLive Demo ... Read More

Advertisements