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

213
Views
How to appear a pop-up only once / browser?

I got a problem. I want to show a pop-up image, at the main page of my website only once. If i reload the page, the image should not appear, but it appear again. How can i solve this problem? I tried with session cookie but it didn't help me.

    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>

I can close the popup, but if i go to other page at my site and than go back it appear again, and I don't want to show it again. Just only once/browser.

I mean, if i close the Google chrome and reopen the website, the pop up should appear again. Any ideas?

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

0

The problem with your code is that whenever you reload the page you run this piece of code:

document.cookie = "cookie=appear";

So whatever the cookie was it would have been set to "cookie=appear";

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>

This worked for me.

about 4 years ago · Juan Pablo Isaza Report

0

use LocalStorage for storing info/recording the number of visits

about 4 years ago · Juan Pablo Isaza Report

0

Have you tried to use a Bootstrap Modal instead? It helps heaps and could save a lot of time:)

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!