Location: toString() 方法

Baseline 已廣泛支援

此功能已相當成熟,可在多種裝置和瀏覽器版本上使用。自 ⁨2016 年 7 月⁩起,所有瀏覽器均已支援此功能。

toString() 方法是 Location 介面的字串化方法,它返回一個包含完整 URL 的字串。它是 Location.href 的只讀版本。

語法

js
toString()

引數

無。

返回值

一個表示物件 URL 的字串。

示例

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'

規範

規範
HTML
# dom-location-href-dev

瀏覽器相容性