The location Object

The location Object

by Mehmetcan Sinir

JavaScript

//the location object
//the location object is a property of both window and document
location.href="http://www.google.com";
location.assign("http://www.google.com");

//assume we are starting at "http://www.wrox.com/WileyCDA"

//changes URL to "http://www.wrox.com/WileyCDA/#section1"
location.hash = "#section1";
//changes URL to "http://www.wrox.com/WileyCDA/?q=javascript"
location.search = "?q=javascript";
//changes URL to "http://www.yahoo.com/WileyCDA"
location.hostName = "www.yahoo.com";
//changes URL to "http://www.yahoo.com/mydir"
location.pathName = "mydir";
//changes URL to "http://www.yahoo.com:8080/mydir"
location.port = "8080";