Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7413069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:38:20+00:00 2026-05-29T06:38:20+00:00

I got a script like that (I use jQuery cookie js to set cookies)

  • 0

I got a script like that (I use jQuery cookie js to set cookies) to display layer on first visit.

<script type="text/javascript">
    $(document).ready(function() {
        var visited = $.cookie('visited', 'yes', { expires: 1, path: '/' });

        if (visited == null) {
            $('.newsletter_layer').show();
            $.cookie('visited', 'yes'); 
            alert($.cookie("visited"));         
        }
    });
</script>

Unfortunatelly something is not working. I think something is wrong with the if statement. Anyone have idea what can be wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T06:38:21+00:00Added an answer on May 29, 2026 at 6:38 am

    Because you are creating the cookie, it will never be null. You need to change your logic to first check if the cookie exists. If not, show the .newsletter_layer element, then set the cookie value:

    <script type="text/javascript">
        $(document).ready(function() {
            // check cookie
            var visited = $.cookie("visited")
    
            if (visited == null) {
                $('.newsletter_layer').show();
                alert($.cookie("visited"));         
            }
    
            // set cookie
            $.cookie('visited', 'yes', { expires: 1, path: '/' });
        });
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a bash script that reads input from a file like this: while
Right now I've got a mod_wsgi script that's structured like this.. def application(environ, start_response):
I've got some trouble with jQuery script on my Asp.net page. During first load
I've got a script that takes a user uploaded RTF document and merges in
I've got a script that dynamically calls and displays images from a directory, what
I've got a script executing on $(document).ready() that's supposed to vertically align block element
I've got a script control that has a control embedded within it that exposes
I've got a script that sets some session values before redirecting to / using
I am learning JQuery, and I have checked out that JQUery has got a
I've got a script that needs to reference the initial commit in a repository.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.