Proprietà window.location.hostname

Definizione e uso

location.hostname Proprietà che restituisce l'host dell'URL (indirizzo IP o nome di dominio).

Puoi anche impostare location.hostname Proprietà, naviga alla stessa URL con un nuovo nome di host.

Vedi anche:

Proprietà location.host

Esempio

Restituire il nome dell'host dell'URL corrente:

let hostname = location.hostname;

Prova da solo

Sintassi

Restituire l'attributo hostname:

location.hostname

Impostare l'attributo hostname:

location.hostname = hostname

Valore dell'attributo

Valore Descrizione
hostname Il nome dell'host dell'URL.

Valore di ritorno

Tipo Descrizione
Stringa L'host dell'URL (indirizzo IP o nome di dominio).

Supporto browser

Tutti i browser supportano location.hostname:

Chrome IE Edge Firefox Safari Opera
Chrome IE Edge Firefox Safari Opera
Supporto Supporto Supporto Supporto Supporto Supporto