Or, "Where Am I and How Did I Get Here?" or, "Where Do I Go Now?"
This call gives you the entire URL location at this moment for the document now being displayed on screen.
It is important to know that this URL is platform independent. If you are viewing a local file on your own computer, it will return the entire file path on your system.
If you are viewing a file on the internet, it will generally take the form of:
will set str as follows:
But if you are viewing a file on your own system, it will take the general form of:
Note that the local path begins with file: and is followed by three slashes, while the internet paths are followed by just two slashes.
This is the very same information displayed on the location: line at the top of your browser.
Built-in Calls that Parse the .href
Now, of course you can simply parse the entire path returned by the browser into its component parts, using string syntax. However, there are built-in parsers that will return the various parts without you having to do so:
Using these location calls, this location.href is parsed into its various components automatically as shown just below:
This little script incorporates the various location calls so that you can see them in action:
<TITLE>Using the Location Parsing
<TABLE BORDER=0 WIDTH=486>
Calls to Parse the Location</B>
<BR>(A virtual search string has been added for
demo only. If being run locally, items with "*"
will display nothing while those with ** will
<!-- Hide from JS-Impaired Browsers
+'This document\'s <B>location.href</B> '
+'is <FONT COLOR="blue">'
+'<P>This document\'s <B>location.pro'
+'tocol</B> is <FONT COLOR="blue">'
+'<P>* This document\'s <B>location.ho'
+'st</B> is <FONT COLOR="blue">'
+'<P>** This document\'s <B>location.ho'
+'stName</B> is <FONT COLOR="blue">'
+'<P>* This document\'s <B>location.port'
+'</B> is <FONT COLOR="blue">'
+'<P>** This document\'s <B>location.path'
+'Name</B> is <FONT COLOR="blue">'
+'<P>* This document\'s <B>location.has'
+'h</B> is <FONT COLOR="blue">'
+'<P>This document\'s <B>location.sea'
+'rch</B> is <FONT COLOR="blue">'
// End Hiding -->
Click Here to See This Script