JavaScript Browser Objects

Browser Objects The Browser Object Model (BOM) is used for JavaScript to interact with the browser. All browsers nowadays use the same methods and properties for JavaScript interactivity, thus there is no official standard released for BOM to date. Window Object: The window is the default object of the browser and is supported by all … Read more

Exceptions in JavaScript

JavaScript’s latest version added exception-handling capabilities. It provides try, catch and finally blocks to handle the exceptions. Syntax of a try block with catch block: try{ //block of statements }catch(exception_var){ } Syntax of a try block with a final block: try{ //block of statements } finally { } Syntax of try block with catch and … Read more

Print a Web Page using Javascript

The print() method is used to print the contents of the current window. w=window.open(); w.document.write(document.getElementsByClassName(‘test’)[0].innerH‌​TML); w.print(); w.close(); Related topics: What is JavaScript? JavaScript advantages and disadvantages Javascript External file Javascript isNaN() Javascript Undefined and Null Javascript Create object JavaScript access cookie Javascript read cookie Javascript get cookie by name Javascript detete cookie Javascript redirect URL … Read more

Redirect a URL using Javascript

We can use window.location.replace(…) or window.location.href to redirect a URL using JavaScript. //Behave as an HTTP redirect window.location.replace(“https://www.w3schools.blog”); //Behave as clicking on a link window.location.href = “https://www.w3schools.blog”; Related topics: What is JavaScript? JavaScript advantages and disadvantages Javascript External file Javascript isNaN() Javascript Undefined and Null Javascript Create object JavaScript access cookie Javascript read cookie Javascript … Read more

Delete a Cookie using Javascript

JavaScript can create, read, and delete cookies with the document.cookie property. Syntax: document.cookie = “key1 = value1; key2 = value2; expires = date”; Where: expires: is an optional attribute that specifies the date of cookie expiration. Example: document.cookie = “username=jai; We don’t have to specify a cookie value when we want to delete a cookie. We have … Read more

Get Cookie by name in Javascript

JavaScript can create, read, and delete cookies with the document.cookie property. Syntax: document.cookie = “key1 = value1; key2 = value2; expires = date”; Where: expires: is an optional attribute that specifies the date of cookie expiration. Example: document.cookie = “username=jai; Geta cookie by name in javascript function getCookie(cookieName) { let cookie = {}; document.cookie.split(‘;’).forEach(function(el) { let [key,value] … Read more

Read Cookie using Javascript

JavaScript can create, read, and delete cookies with the document.cookie property. Syntax: document.cookie = “key1 = value1; key2 = value2; expires = date”; Where: expires: is an optional attribute that specifies the date of cookie expiration. Example: document.cookie = “username=jai; Read a cookie using javascript var x = document.cookie; Related topics: What is JavaScript? JavaScript advantages and … Read more

How to create a Cookie using JavaScript?

JavaScript can create, read, and delete cookies with the document.cookie property. Syntax: document.cookie = “key1 = value1; key2 = value2; expires = date”; Where: expires: is an optional attribute that specifies the date of cookie expiration. Example: document.cookie = “username=jai; Related topics: What is JavaScript? What are the advantages of JavaScript? What are the disadvantages of JavaScript? … Read more

Access Cookie using Javascript

Yes, we can access cookies using javascript. Javascript Document object have cookie property. We can read, create, modify, and delete the cookies or cookies that apply to the current web page using the cookie property of the Document object. Related topics: What is JavaScript? JavaScript advantages and disadvantages Javascript External file Javascript isNaN() Javascript Undefined … Read more

Difference between Undefined Value and Null Value

Undefined variable: A variable that is declared but the value is not defined for that. Undefined value: A value that is not defined and has no keyword is known as an undefined value. Example: var testNum; console.log(testNum); // undefined Note: Undefined is of the type undefined. var testNum; console.log(typeof testNum); // undefined Null value: A value … Read more