-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSTARKK.js
More file actions
36 lines (26 loc) · 1.17 KB
/
STARKK.js
File metadata and controls
36 lines (26 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
document.getElementById("linkContacto").addEventListener("click", (e) => {
e.preventDefault(); // 🚫 evita navegación
console.log("Click interceptado");
});
// Selecciona TODOS los elementos que tengan la clase "link"
document.querySelectorAll(".link").forEach(link => {
// A cada enlace le agrega un evento cuando se hace clic
link.addEventListener("click", e => {
// Evita el comportamiento normal del <a>
// (o sea, que el navegador cargue otra página)
e.preventDefault();
// Obtiene la URL guardada en el atributo data-url del enlace
// Ejemplo en HTML: <a class="link" data-url="acerca.html">Acerca</a>
const url = link.dataset.url;
// Hace una petición HTTP a esa URL sin recargar la página
fetch(url)
// Convierte la respuesta del servidor en texto (HTML)
.then(res => res.text())
// Recibe el HTML y lo procesa
.then(html => {
// Inserta el contenido HTML recibido
// dentro del elemento <main> de la página actual
document.querySelector("main").innerHTML = html;
});
});
});