Registration window restriction

I have implemented a sign-up modal on a Bootstrap website and am looking to restrict the number of times visitors see it to twice per session instead of on every page, as well as hiding it once a visitor has subscribed. The modal will appear after 5 seconds of opening a web page and will only close when a user clicks the close button.

//Code for Modal
$(document).ready(function () {
    //Setting delay for background overlay fade in
    $("#bkgOverlay").delay(5000).fadeIn(400);
    //Setting delay for popup fade in
    $("#delayedPopup").delay(6000).fadeIn(400);
    //Hiding dialogue and background on close button click
    $("#btnClose").click(function (e) {
        HideDialog();
        e.preventDefault();
    });
});
//Function to hide the modal popup with close button
function HideDialog() {
    $("#bkgOverlay").fadeOut(400);
    $("#delayedPopup").fadeOut(300);
}
html {
    background-color: #333;
}

h2 {
    text-align: center;
}

/****Modal Styles****/
/*Background Overlay*/
.backgroundOverlay {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    height: 100%;
    width: 100%;
    margin: 0;
    padding: 0;
    background: #000000;
    opacity: .85;
    filter: alpha(opacity=85);
    -moz-opacity: .85;
    z-index: 101;
    display: none;
}
/*Popup Window*/
.delayedPopupWindow {
    display: none;
    position: fixed;
    width: auto;
    max-width: 480px;
    height: 310px;
    top: 50%;
    left: 50%;
    margin-left: -260px;
    margin-top: -180px;
    background-color: #efefef;
    border: 2px solid #333;
    z-index: 102;
    padding: 10px 20px;
}
/*Closing Button*/
#btnClose {
    width:100%;
    display: block;
    text-align: right;
    text-decoration: none;
    color: #BCBCBC;
}
/*Hover State for Closing Button*/
#btnClose:hover {
    color: #c90c12;
}
/*Headline and Paragraph Styling*/
#delayedPopup > div.formDescription {
    float: left;
    display: block;
    width: 44%;
    padding: 1% 3%;
    font-size: 18px;
    color: #666;
    clear: left;
}
/*Styling for Form Headline*/
#delayedPopup > div.formDescription h2 {
    color: #444444;
    font-size: 36px;
    line-height: 40px;
}

/*MailChimp Signup Form*/
/*Signup Form Body*/
#delayedPopup #mc_embed_signup {
    float: left;
    width: 47%;
    padding: 1%;
    display: block;
    font-size: 16px;
    color: #666;
    margin-left: 1%;
}
/*Styling for Signup Form Inputs*/
#delayedPopup #mc-embedded-subscribe-form input {
    width: 95%;
    height: 30px;
    font-size: 18px;
    padding: 3px;
    margin-bottom: 5px;
}
/*Styling for Input Hover State*/
#delayedPopup #mc-embedded-subscribe-form input:hover {
    border:solid 2px #97c1c0;
    box-shadow: 0 1px 3px #AAAAAA;
}
// More CSS styling...

//HTML code for signup form
<html lang="en">
<head>
    <title>HOME</title>
    -more HTML code here-
  </body>

</html>

Answer №1

Utilize the jquery-cookie plugin created by carhartl.

Before displaying the modal, check if a cookie exists. If it does, refrain from showing the modal. If not, create a new cookie and then display the modal.

$(document).ready(function() {
if ($.cookie('modal_shown') == null) {
    $.cookie('modal_shown', 'yes', { expires: 7, path: '/' });
    $('#bkgOverlay').modal('show');
}

});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

assigning attributes to web addresses

Is there a way to set a style property for webpages by targeting addresses that contain /index.php/projecten/ instead of specifying each complete address in the code? Currently, I am using the following code: <ul class="subnavlist" style="display: &l ...

Make the element switch from hidden to visible when hovering over it using CSS

I had a challenge to only show some rating text on my website when I hovered over it. Being new to coding with CSS and JavaScript, I was experimenting with overriding styles using the Stylebot extension in Chrome. I encountered an issue while trying to mo ...

Creating PDF files from elements using Puppeteer JS

In my quest to master the usage of Puppeteer within a Vue.js application, I am facing a challenge. I am able to create a PDF based on the entire page successfully, but I am struggling to generate a PDF for a specific element on the page. Is there a method ...

Tips for transferring information to a node server

Currently, I am working with Express and facing the challenge of dynamically sending data to the app.get() method. Specifically, on my index page, there is a list of topics, and upon clicking one, I need to send the name of that element as the required dat ...

Stopping form submission on a jQuery form

I am in the process of implementing a password control feature on a login form using jQuery and ajax. This is the current script I have: $(document).ready(function() { $("#login-form").submit(function(e) { var csrftoken = getCookie('csr ...

Guide on how to showcase JSON data using vanilla JavaScript within the Laravel framework

As a beginner in Laravel, I am looking to pass JSON data from my controller using vanilla JavaScript to my view blade. However, I am unsure of the steps to accomplish this. Below is an example of my controller: public function index(Request $request) { ...

How can CORS be activated? Is it through the server or Javascript, and where does this

Currently, I am testing my ReactJS website on localhost:3333 and my ASP.NET Web API 2 on localhost:54690. I am utilizing axios for my AJAX requests, but encountering an error when making a request. XMLHttpRequest cannot load http://localhost:54690/api/ ...

Creating a custom inline style button in Froala Editor

As a UX Designer with experience in frontend development, I am currently working on an online editor proof of concept for a usability study. One of the key findings so far is that users are requesting a button that can automatically apply the corporate fon ...

Error encountered in SelectInput.js file of React MUI 4: line 340 - TypeError: Unable to access properties of undefined (specifically 'value')

An issue arises when an empty array is provided as the options. The error message: SelectInput.js:340 Uncaught TypeError: Cannot read properties of undefined (reading 'value') at SelectInput.js:340:1 at Array.map (<anonymous>) ...

Is there a way to remove this specific element from an inherited hyperlink?

My website can be found at whensayfeed.meteor.com. Each post on the site is enclosed within an <a></a> element. The heart symbol on the right side of each post is intended to be a "like button" that users can click on. However, because it is ...

There was a mistake: _v.context.$implicit.toggle cannot be used as a function

Exploring a basic recursive Treeview feature in angular4 with the code provided below. However, encountering an error when trying to expand the child view using toggle(). Encountering this exception error: ERROR TypeError: _v.context.$implicit.toggle i ...

Create a social chat platform similar to Facebook by implementing a chat box feature with the help of AJAX, jQuery

Currently, I have developed a chat box with two persistent issues. Despite my attempts to rectify them, I am unable to find a solution. Below, I will outline my code, focusing on the HTML section where the chat box, chat text area, and chat members are dis ...

Tips for resolving the issue of "Unable to assign property '_DT_CellIndex' to undefined in Jquery Datatable"

<?php if(mysqli_num_rows($result)>0) {?> <table class="table table-striped" id="example" align="center"> <tr> <thead> <th style=&quo ...

Steps for adding an onclick function to a collection of div elements

My current project involves utilizing the Flickr API and I am interested in creating a popup div that opens when clicking on each image. The goal is to display the image in a larger form, similar to how it's done using Fancybox. I'm looking for ...

Tips for resetting/removing a Chart.js canvas in a React JSX element

I have encountered an issue with chart.js while working on a specific report. Whenever I switch pages to another page that includes chartjs elements and then switch back, the chart displays data labels on the data points like "x: number, y: number". Afte ...

Correct Way to Use 'useState' in Formik's 'onSubmit' Function?

I recently encountered an issue while using Formik in my Next.js application. Specifically, I am facing a problem with the submit `Button` component, which accepts a `showSpinner` prop to control its behavior. When set to true, the button is disabled and d ...

ng-class not updating using a combination of object and string

I am just starting to learn angular js and I recently came across the ng-class directive. Below is an example of how I have used it: ng-class="[{'highlighter-row-Class' : (file.id == 1 && file.processed), 'bold-row-Class' : ...

Guide on invoking an ajax function within a for loop

As someone new to ajax and JavaScript, my goal is to call an ajax function multiple times to retrieve specific data from a resource and then store all of that data in an array for later use in my code. Below is the code I have so far: var arr = []; var us ...

Empty Media Viewer

I am encountering an issue with setting up a code, as it only displays a blank white page. Any suggestions on what might be causing this problem in the setup and assistance in resolving it would be greatly appreciated. <script type="text/javascript ...

Why are the elements not found by their id when I check them, even though they were created dynamically using an ajax-generated form with php-inserted values through a

How can I prepopulate form fields displayed in a modal view using jQuery after retrieving the form HTML with an AJAX query? I am trying to set the values through a JavaScript function that retrieves PHP-generated values via document.getElementById. However ...