location.toString()

The toString() stringifier method of the Location interface returns a string containing the whole URL. It is a read-only version of Location.href.

Syntax

toString()

Parameters

None.

Return value

None (undefined).

Examples

// Let's imagine an <a id="myAnchor" href="/en-US/docs/Location/toString"> element is in the document
var anchor = document.getElementById("myAnchor");
var result = anchor.toString(); // Returns: 'https://developer.mozilla.org/en-US/docs/Location/toString'

Specifications

Specification
HTML Standard
# dom-location-href-dev

Browser compatibility

BCD tables only load in the browser