The toString()
stringifier method of the Location
interface returns a string containing the whole URL. It is a read-only version of Location.href
.
location.toString()
Syntax
toString()
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
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
toString |
52
|
12
|
22
|
11
Intranet sites are set to Compatibility View, which will emulate IE7 and omit
window.location.toString .
|
39
|
1
|
52
|
52
|
22
|
41
|
1
|
6.0
|
© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Location/toString