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

Location origin Property

Location Object Reference Location Object

Example

Return the protocol, hostname and port number of a URL. Assume that the current URL is http://www.w3schools.com:4097/test.htm#part2:

var x = location.origin;

The result of x will be:

http://www.w3schools.com:4097


Definition and Usage

The origin property returns the protocol, hostname and port number of a URL.

Note: If the port number is not specified in the URL (or if it is the scheme's default port - like 80, or 443), some browsers will not display the port number.

Note: This property is read-only.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The origin property is supported in all major browsers, except Internet Explorer.

Note: The origin property is not supported in Opera version 12 (and earlier).


Syntax

location.origin

Return Value

Type Description
String The protocol (including ://), the domain name (or IP address) and port number (including the colon sign (:) of the URL. For URL's using the "file:" protocol, the return value differs between browsers


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