Location: phương thức toString()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2016.

Phương thức toString() stringifier của giao diện Location trả về một chuỗi chứa toàn bộ URL. Nó là phiên bản chỉ đọc của Location.href.

Cú pháp

js
toString()

Tham số

Không có.

Giá trị trả về

Một chuỗi đại diện cho URL của đối tượng.

Ví dụ

js
// Giả sử đoạn mã này được thực thi trên https://example.com/path?search#hash
const result = window.location.toString(); // Trả về: 'https://example.com/path?search#hash'

Thông số kỹ thuật

Specification
HTML
# dom-location-href-dev

Tương thích trình duyệt