Lokasi jendela.href
Contoh
Dapatkan URL halaman saat ini:
let url = location.href;
Setel URL halaman saat ini:
location.href = "https://www.w3schools.com";
Lebih banyak contoh di bawah ini.
Definisi dan Penggunaan
Properti location.href
menetapkan atau mengembalikan seluruh URL halaman saat ini.
Sintaksis
Kembalikan properti href:
location.href
Setel properti href:
location.href = URL
Nilai properti
Parameter | Description |
URL |
An absolute URL like: http://www.example.com/default.htm A relative URL like default.htm An anchor URL like location.href="#top" A new protocol like: ftp://someftpserver.com mailto:[email protected] file://host/path/example.txt |
Nilai Kembali
Jenis | Keterangan |
Sebuah benang | URL lengkap halaman, termasuk protokol (seperti https://). |
Lebih Banyak Contoh
Setel nilai href untuk menunjuk ke jangkar di dalam halaman:
location.href = "#top";
Atur nilai href untuk menunjuk ke alamat email (akan terbuka dan membuat pesan email baru):
location.href = "mailto:[email protected]";
Dukungan Peramban
location.href
didukung di semua browser:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |