Location: toString()

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

Syntax

string = object.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

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.
?
1
52
52
22
?
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