The URLUtils.pathname property is a DOMString containing an initial '/' followed by the path of the URL.
Note: This feature is available in Web Workers.
Syntax
string = object.pathname; object.pathname = string;
Examples
Basic usage
// Let's an <a id="myAnchor" href="https://developer.mozilla.org/en-US/docs/URLUtils.pathname"> element be in the document
var anchor = document.getElementByID("myAnchor");
var result = anchor.pathname; // Returns:'/en-US/docs/URLUtils.pathname'
Get the folder portion of a pathname string
Library
function getFolder (oTarget, nDeltaUp) {
return oTarget.pathname.replace(new RegExp("(?:\\\/+[^\\\/]*){0," + ((nDeltaUp || 0) + 1) + "}$"), "/");
}
Syntax
getFolder(URLObject[, upFor])
Description
Shows the folder part of a pathname property.
Parameters
URLObject- The object with a
pathnameproperty (string). upForOptional- Move up from the current path for n levels (positive integer number).
Example
alert(window.location.pathname); // "/en-US/docs/Web/API/URLUtils.pathname" alert(getFolder(window.location)); // "/en-US/docs/Web/API/" alert(getFolder(window.location, 2)); // "/en-US/docs/" alert(getFolder(window.location, 3)); // "/en-US/" alert(getFolder(window.location, 4)); // "/" alert(getFolder(window.location, 27)); // "/"
Specifications
| Specification | Status | Comment |
|---|---|---|
| URL The definition of 'URLUtils.pathname' in that specification. |
Living Standard | Initial definition. |
Browser compatibility
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
| Basic support | Not supported [1] | 22 (22) [1] | Not supported [1] | Not supported [1] | Not supported [1] |
| Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|
| Basic support | Not supported [1] | Not supported [1] | 22.0 (22) [1] | Not supported [1] | Not supported [1] | Not supported [1] |
[1] Though not grouped in a single abstract interface, this method is directly available on the interfaces that implement it, if this interface is supported.
See also
- The
URLUtilsinterface it belongs to.
Document Tags and Contributors
Tags:
Contributors to this page: Brettz9, chrisdavidmills, teoli, fusionchess, mturnwall, Kartik_Chadha, mikemcg
Last updated by:
Brettz9,

