Location href Property
Example
Return the entire URL (of the current page):
var x = location.href;
The result of x will be:
Try it Yourself »
More "Try it Yourself" examples below.
Definition and Usage
The href property sets or returns the entire URL of the current page.
Browser Support
Property | |||||
---|---|---|---|---|---|
href | Yes | Yes | Yes | Yes | Yes |
Syntax
Return the href property:
location.href
Set the href property:
location.href=URL
Property Values
Value | Type | Description |
---|---|---|
URL | String |
Specifies the URL of the link.
Possible values:
|
Technical Details
Return Value: | A String, representing the entire URL of the page, including the protocol (like http://) |
---|
More Examples
Example
Set the href value to point to another web site:
location.href = "http://www.cnn.com";
Try it Yourself »
Example
Set the href value to point to an anchor within a page:
location.href = "#top";
Try it Yourself »
Example
Set the href value to point to an email address (will open and create a new email message):
location.href = "mailto:someone@example.com";
Try it Yourself »
Location Object