Javascript provides many methods to obtain and change the current URL, these methods use the Location object which is a property of the Window object, you can create a new Location object that has the current URL like this:
var LocationActual=window.location;
or
window.location.href
or
document.URL;
Behavior may depend on the browser
Basic structure of a URL:
<protocol>//<hostname>:<port>/<pathname><search><hash>
1.- Protocol - Specifies the name of the protocol to be used to access the internet resource (HTTP without SSL or HTTPS with SSL)
2.- hostname - Specifies the host that owns the resource, for example www.stackoverflow. A server provides services using the host name.
3.- port - A port number used to recognize a specific process to which a message from a network or internet is redirected when it arrives at the server.
4.- pathname - Provides information about the specific resource within the host to which the web client wants to access, for example /index.html
5.- query - Follow the path of the component and provide a chain of information that the resource can use for the same purpose (example, search parameters or data to process)
6.- hash - Fragment identifier, includes the symbol (#)
With these properties you can access all these components of the URL
hash - Gets or sets the fragment identifier
host - Get or set the hostname and port of a URL
hostname - Get or set the hostname of a URL
href - Get or set the entire URL
pathname - Get or set the path name of a URL
port - Gets or sets the port number that the server uses
for the URL
protocol - Get or set the protocol of a URL
search - Gets or sets the query part (or query) of a
URL
Retrieved from: link
See also
link
link