Atribut location.href Window
- Halaman Sebelumnya hostname
- Halaman Berikutnya origin
- Kembali ke TINGKAT ATAS Window Location
Definisi dan penggunaan
location.href
Pengaturan atribut atau pengembalian URL keseluruhan halaman saat ini.
Contoh
Contoh 1
Ambil URL halaman saat ini:
let url = location.href;
Contoh 2
Atur URL halaman saat ini:
location.href = "";
Contoh 3
Atur nilai href untuk mengarahkan ke titik di halaman:
location.href = "#top";
Contoh 4
Atur nilai href untuk mengarahkan ke alamat surel (akan membuka perangkat lunak dan membuat surel baru):
location.href = "mailto:someone@example.com";
Sintaks
Kembalikan atribut href:
location.href
Atur atribut href:
location.href = URL
Nilai atribut
Nilai | Deskripsi |
---|---|
URL |
URL absolut, contoh: http://www.example.com/index.html URL relatif, contoh: index.html URL anjut, seperti: location.href="#top" Protokol baru, seperti: ftp://someftpserver.com mailto:someone@example.com file://host/path/example.txt |
Nilai kembalian
Tipe | Deskripsi |
---|---|
String | URL penuh halaman, termasuk protokol (seperti https://). |
Dukungan Peramban
Semua peramban mendukung location.href
:
Chrome | IE | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
Chrome | IE | Edge | Firefox | Safari | Opera |
Dukungan | Dukungan | Dukungan | Dukungan | Dukungan | Dukungan |
- Halaman Sebelumnya hostname
- Halaman Berikutnya origin
- Kembali ke TINGKAT ATAS Window Location