Atributo Window location.hostname

Definición y uso

location.hostname Atributo que devuelve el host del URL (dirección IP o nombre de dominio).

También se puede configurar location.hostname Atributo, navegue a la misma URL con un nuevo nombre de host.

Vea también:

Atributo location.host

Ejemplo

Devolver el nombre del host del URL actual:

let hostname = location.hostname;

Prueba personal

Sintaxis

Devolver el atributo hostname:

location.hostname

Configurar el atributo hostname:

location.hostname = hostname

Valor del atributo

Valor Descripción
hostname El nombre del host del URL.

Valor devuelto

Tipo Descripción
Cadena El host del URL (dirección IP o nombre de dominio).

Compatibilidad del navegador

Todos los navegadores lo admiten location.hostname

Chrome IE Edge Firefox Safari Opera
Chrome IE Edge Firefox Safari Opera
Soporte Soporte Soporte Soporte Soporte Soporte