Location | Htmldom

 

Descripción

El interface Location representa la URL del documento que está cargado en el navegador. Al interface Location también se puede acceder desde Window.location y Document.location

Sintaxis

Location

Constructores

  • N/A

Propiedades

Métodos

Eventos

Ejemplo

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Controlar cambio hash</title>
</head>
<body onhashchange="cambioHash();">

  <h1>Controlar Navegaciones SPA por Hash</h1>

  <button onclick="nuevoHash('P1');">Página 1</button> 
  <button onclick="nuevoHash('P2');">Página 2</button>
  <button onclick="nuevoHash('P3');">Página 3</button>

  <br/><br/>

  <div id="mensaje"></div>

  <script>
    function nuevoHash(nombre) {
      location.hash = "#"+nombre;
    }

    function cambioHash(){
      document.getElementById("mensaje").innerHTML = "Navegación al hash '" + location.hash + "'";
    }
  </script>

</body>
</html>

Artículos