X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

Location href Property

Location Object Reference Location Object

Example

Return the entire URL (of the current page):

var x = location.href;

The result of x will be:


Try it yourself »


Definition and Usage

The href property sets or returns the entire URL of the current page.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The href property is supported in all major browsers.


Syntax

Return the href property:

location.href

Set the href property:

location.href=URL

Value Type Description
URL String Specifies the URL of the link.

Possible values:

  • An absolute URL - points to another web site (like location.href="http://www.example.com/default.htm")
  • A relative URL - points to a file within a web site (like location.href="default.htm")
  • An anchor URL - points to an anchor within a page (like location.href="#top")
  • A new protocol - specifies a different protocol (like location.href="ftp://someftpserver.com", location.href="mailto:someone@example.com" or location.href="file://host/path/example.txt")

Return Value

Type Description
String The entire URL


Examples

More Examples

Link to another web site
How to set the href value to point to another web site.

Link to an element with a specified id
How to set the href value to point to an anchor within a page.

Open and create a new email message
How to set the href value to point to a mailto: protocol.


Location Object Reference Location Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates FREE Website Templates Free HTML Templates

SHARE THIS PAGE

facebook