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

201
Views
¿Cómo aparece una ventana emergente solo una vez / navegador?

Tengo un problema. Quiero mostrar una imagen emergente en la página principal de mi sitio web solo una vez. Si vuelvo a cargar la página, no debería aparecer la imagen, pero vuelve a aparecer. ¿Como puedó resolver esté problema? Probé con la cookie de sesión pero no me ayudó.

 document.cookie = 'cookie=appear'; if (document.cookie = 'cookie=appear' == 'cookie=appear'){ function close_function(){ document.getElementById("popup").style.display = "none"; document.cookie = 'cookie=notappear'; } } if (document.cookie = 'cookie=notappear' == 'notappear'){ document.getElementById("popup").style.display = "none"; }
 <div id="popup" style="position: fixed; bottom: 0; left: 100px;"><a href="https://www.google.com/"><img class="alignleft" src="folder/picture.jpg" width="300" height="207"></a><button id="close" type="closebutton" onclick="close_function()">X</button></div>

Puedo cerrar la ventana emergente, pero si voy a otra página de mi sitio y luego vuelvo, aparece de nuevo y no quiero volver a mostrarla. Solo una vez/navegador.

Quiero decir, si cierro Google Chrome y vuelvo a abrir el sitio web, la ventana emergente debería aparecer nuevamente. ¿Algunas ideas?

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

El problema con su código es que cada vez que recarga la página, ejecuta este código:

 document.cookie = "cookie=appear";

Entonces, cualquiera que sea la cookie, se habría configurado en "cookie = aparecer";

 const popup = document.getElementById("popup"); if(document.cookie == '' || document.cookie == 'cookie=appear') { popup.style.display = "inline"; } else { popup.style.display = "none"; } function close_function() { document.cookie = "cookie=notappear"; popup.style.display = "none"; }
 <div id="popup" style="position: fixed; bottom: 0; left: 100px;"><a href="https://www.google.com/"><img class="alignleft" src="folder/picture.jpg" width="300" height="207"></a><button id="close" type="closebutton" onclick="close_function()">X</button></div>

Esto funcionó para mí.

about 4 years ago · Juan Pablo Isaza Report

0

use LocalStorage para almacenar información/registrar el número de visitas

about 4 years ago · Juan Pablo Isaza Report

0

¿Has intentado usar un Bootstrap Modal en su lugar? Ayuda mucho y podría ahorrar mucho tiempo :)

about 4 years ago · Juan Pablo Isaza 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!