Location.hostname

In this chapter you will learn:

  1. How to change the hostname of location

Host name

The hostname property can be set with new values that alter the current URL.

Assume starting at http://www.java2s.com/index.htm,

location.hostname = "java2s.com";

changes URL to "http://java2s.com/index.htm"

<!DOCTYPE HTML> /*from   j  av a 2  s .co m*/
<html> 
    <body> 
        <script> 
               location.hostname = "java2s.com"; 

        </script> 
    </body> 
</html>

Next chapter...

What you will learn in the next chapter:

  1. How to change the href property for Location object
Home » Javascript Tutorial » Location
Location
assign method
Location.hash
Location.hostname
Location.href
location.pathname
location.port
location.reload
location.replace()
Location.search