Skip to main content

Posts

Showing posts with the label get base url in JavaScript

How to get base URL in JavaScript?

Hello everyone, I am going to share the code sample to get base URL using the JavaScript . I think this one is very interesting stuff when you developing the web applications. Using this no need to writing  on local base URL and server base URL again and again, The below code help me to prevent the re writing the base URL again and again actually. The live output, go to link   http://embed.plnkr.co/GTwlRC/preview The go detail as given below. var  _baseURL; //This method id used to get the base URL for global constant. function getBaseURL () {       _baseURL= location.protocol + "//" + location.hostname +        (location.port && ":" + location.port) + "/" ;    return baseURL; } The live demo example code as given below < !DOCTYPE html > < html > < head >     < link rel ="stylesheet" href ="style.css"> ...

Prototype in JavaScript

What is Prototype in JavaScript? How to create prototype in JavaScript? The prototype is a fundamental concept of JavaScript and its must to known JavaScript developers and a ll the   JavaScript objects  have an object and its property called prototype and its used to add and the custom functions and property. The example looks like, var employee = function () { //This is a constructor function. } //Crate the instance of above constructor function and assign in a variable var empInstance = new employee(); empInstance.deportment = "IT" ; console .log (empInstance.deportment); //The output of above is IT. The example with prototype as given below. var employee = function () { //This is a constructor function.} employee . prototype . deportment = "IT" ; //Now, for every instance employee will have a deportment. //Crate the instance of above constructor function and assign in a variable var empInstance = new employee()...