Window location.pathname attribute

Definition and usage

pathname Set or return the path name of the URL (page).

Example

Get the current path:

let path x = location.pathname;

Try it yourself

Syntax

Return the pathname attribute:

location.pathname

Set the pathname attribute:

location.pathname = path

Attribute value

Value Description
path The path name of the URL.

Return Value

Type Description
String Current Pathname.

Browser Support

All Browsers Support location.pathname:

Chrome IE Edge Firefox Safari Opera
Chrome IE Edge Firefox Safari Opera
Support Support Support Support Support Support