Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Automatic popup?

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #168110
    samtastic
    Participant

    I’m sure it’s been asked a million times, but I can’t seem to find any codes that do what I want.

    I need it to come up when the site is opened, saying something along the lines of
    WARNING!!!
    The content on this site can be upsetting to some viewers. Please browse at your own risk.”
    Followed by an “I understand” button that lets you stay on the site, and a “Nevermind then” button that takes the visitor back to the previous page they were one.
    I only want it to come up once when they visit, regardless of the page, but I don’t want it popping up every single time the visitor goes to another page without leaving.

    I want it noticable. I don’t want anyone complaining about how they didn’t see the warning.

    Please tell me where I need to put the code, specifically. I’m used to using HTML, but I’m stuck working with CSS, which is still rather new to me.

    #168115
    Paulie_D
    Member

    JS would be the place to start.

    #168127
    usiris
    Participant

    My first reaction is to set a cookie/item in local storage to identify if its their first time on the site. And on page load check to see if that item/cookie exists; if it does, dont display popup, if it doesnt, set cookie and display popup.

    It would be something like this(sudocode for all you must get everything right people):

    $(document).ready(){
    if(window.localstorage existst) {
      if(window.localstorage.getItem(nameOfItem) !== null) {
       //go to normal flow of page
      }
      else {
      //alert here
       window.localstorage.setItem("nameOfItem", "foo");
      }
    }
    else {
     //I have a read cookie function that I use for these events. You can look that up on            your own, here we'll call it readcookie
    
    if(readCookie("nameOfItem")){
    //normal flow of page
    }
    else {
     //alert here
    //create cookie here
    }
    
    }
    
Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.