English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
hrefImposta o restituisce l'URL completo della pagina corrente.
Restituisce l'attributo href:
location.href
Imposta l'attributo href:
location.href = URL
var x = location.href; document.querySelector("#output").innerHTML = x;Prova a vedere‹/›
Tutti i browser supportano completamente l'attributo href:
Attributo | |||||
href | È | È | È | È | È |
Valore | Descrizione |
---|---|
URL | Stringa che specifica l'URL del link. Valori possibili:
|
Valore di ritorno: | Una stringa che rappresenta l'intero URL della pagina, inclusi il protocollo (ad esempio https://) |
---|
Imposta il valore di href per puntare a un altro sito web:
location.href = "https://it.oldtoolbag.com";Prova a vedere‹/›
Imposta il valore di href per puntare all'ancora all'interno della pagina:
location.href = "#top";Prova a vedere‹/›
Questo esempio mostra tutte le proprietà di posizione:
var txt = ""; txt += "<p>Host: \t+ location.host + "</p>"; txt += "<p>Hostname: \t+ location.hostname + "</p>"; txt += "<p>Href: " + location.href + "</p>"; txt += "<p>Origine: " + location.origin + "</p>"; txt += "<p>Percorso: " + location.pathname + "</p>"; txt += "<p>Protocollo: " + location.protocol + "</p>"; txt += "<p>Cerca: " + location.search + "</p>"; document.write(txt);Prova a vedere‹/›
Riferimento alla posizione:Proprietà location.host
Riferimento alla posizione:Proprietà location.hostname
Riferimento alla posizione:Proprietà location.pathname
Riferimento alla posizione:Proprietà location.protocol