location Object

By: Dusty Arlia
Published on Thursday, July 25, 2013, 06:49 AM
Last Updated on Sunday, July 12, 2015 at 2:11 PM
Total Updates: 3

One of the objects in the browser object model (BOM) is the location object. The location object is used to access information about the currently loaded URL, the query string, and more information about the URL request. The location object is also often used to redirect a webpage visitor to a different page. This can be accomplished through the use of the replace() method

Here is the JavaScript code to enumerate the location object's properties:

for (propt in location) {
document.write("Location property: " + propt + " = " + location[propt] + "<br />\n"); 
}

And here is the output of location's properties. I'm using Google Chrome:

Location property: assign = function () { [native code] }
Location property: replace = function () { [native code] }
Location property: reload = function () { [native code] }
Location property: ancestorOrigins = [object DOMStringList]
Location property: origin = http://fiddle.jshell.net
Location property: hash = 
Location property: search = 
Location property: pathname = /_display/
Location property: port = 
Location property: hostname = fiddle.jshell.net
Location property: host = fiddle.jshell.net
Location property: protocol = http:
Location property: href = http://fiddle.jshell.net/_display/

Comments:

Ad: