Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

176
Views
¿Cómo hacer que un código JavaScript que cambia el diseño del sitio se aplique a todas las páginas?

En mi página de índice, cuando hago clic en un botón, el fondo de la página se vuelve negro, pero no en las otras páginas, incluso si vinculo el archivo .js a todos los documentos html. ¿Cómo hago para que el fondo se vuelva negro en todas las páginas al hacer clic en un botón?

Esto es lo que tengo hasta ahora

 function myFunction() { document.getElementsByTagName("body")[0].style.cssText = "background: black;" }
 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <link rel="stylesheet" href="style.css"> <style> body { background: white; } </style> </head> <body> <button id="button" onclick="myFunction()">Change to black</button> </body> </html>

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Puede guardar el color de fondo en localStorage y leerlo al cargar la página. Cada vez que navega a otra página de su sitio, que carga ese script, leerá el valor almacenado y cambiará el color de fondo en consecuencia.

Guión (personalizar.js):

 function setBGColor() { var bgColor = localStorage.getItem("bgColor"); document.body.style.backgroundColor = bgColor; } function changeBGColor(newColor) { localStorage.setItem("bgColor", newColor); setBGColor(); } setBGColor();

En tu HTML:

 ... <body> <button id="button" onclick="changeBGColor('black')">Change to black</button> </body>
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!