How to Remove a Subdomain in JavaScript

How to Remove a Subdomain in JavaScript thumbnail
Use Javascript to remove subdomains from domain names.

The object oriented scripting language Javascript is used in Web development to create dynamic websites. Javascript allows programming functionality to be added to HTML pages making websites more versatile than originally designed. Javascript code is directly embedded in HTML source files and can be executed by most web browsers. With Javascript, the subdomain of a domain name can be removed to find the root domain. Subdomains are used to organize information in websites and are part of the larger domain.

Things You'll Need

  • Text editor
  • Web browser
Show More

Instructions

    • 1

      Open the HTML file you wish to add Javascript to in your text editor.

    • 2

      Create the Javascript tags in the body of the HTML file by typing the following in the text editor: <script type="text/JavaScript"> </script>. The tags tell the Web browser to execute Javascript. The remainder of the program will be written in between these tags.

    • 3

      Save the domain name to a variable. An example code is the following:

      var domain = "http://subdomain.rootdomain.com"

      Replace "http://subdomain.rootdomain.com" with your domain name in the code example.

    • 4

      Find the first occurrence of the dot in the domain name by typing the following:

      var loc = domain.indexOf(".");

    • 5

      Find the root domain by extracting everything to the right of the first dot in the domain name by writing the following code:

      var rootDomain = domain.substring(loc + 1);

Related Searches:

References

  • Photo Credit Comstock/Comstock/Getty Images

Comments

Related Ads

Featured