W3cubDocs

/Web APIs

location: toString() method

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

js

toString()

Parameters

None.

Return value

A string representing the object's URL.

Examples

js

// Let's imagine this code is executed on https://example.com/path?search#hash
const result = window.location.toString(); // Returns: 'https://example.com/path?search#hash'

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
11Intranet 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–2023 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