English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
hostImpostare o restituire il nome host e il numero di porta dell'URL.
Attenzione:Se non è stato specificato l'attributo host nell'URL, non verrà restituito il numero di porta.
Restituire l'attributo host:
location.host
Impostare l'attributo host:
location.host = hostname:port
var x = location.host; document.querySelector("#output").innerHTML = x;Prova a vedere‹/›
Tutti i browser supportano completamente l'attributo host:
Attributo | |||||
host | È | È | È | È | È |
Valore | Descrizione |
---|---|
hostname:port | Stringa che specifica il nome host e il numero di porta dell'URL |
Valore di ritorno: | Una stringa che rappresenta il nome del dominio e il numero di porta o l'indirizzo IP dell'URL |
---|
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 posizione:Proprietà location.href
Riferimento posizione:Proprietà location.hostname
Riferimento posizione:Proprietà location.pathname
Riferimento posizione:Proprietà location.protocol