How to Display A Popup Only Once Per User



Display A Popup Only Once Per User with a working example

Working example:



<!-- Bootstrap Modal -->
<div class="modal fade" id="myModal1" role="dialog">
<div class="modal-dialog">
<!-- Modal content -->
<div class="modal-content">
<!-- Modal header -->
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title text-primary"></h4>
</div>
<!-- Modal body -->
<div class="modal-body">
                <img src="https://statinfer.com/wp-content/uploads/dummy-user.png" alt="">
</div>
<!-- Modal footer -->
<div class="modal-footer">
<button type="button" class="btn btn-default btn-sm" data-dismiss="modal"> Close </button>
</div>
</div> <!-- // .modal-content -->
</div> <!-- // .modal-dialog -->
</div> <!-- // #myModal -->


<script>
// Original code by Simon. You can check the original code here https://codepen.io/html5andblog/pen/qEqdqO?editors=1010
// Altered and Edited for Bootstrap Modal
// 22 feb 2017

// init
jQuery(document).ready(function(){

// Start
// sessionStorage.getItem('key');
if (sessionStorage.getItem("story") !== 'true') {
// sessionStorage.setItem('key', 'value'); pair
sessionStorage.setItem("story", "true");
// Calling the bootstrap modal
$("#myModal1").modal();
}
// End

// Do not include the code below, it is just for the 'Reset Session' button in the viewport.
// This is same as closing the browser tab.
$('#reset-session').on('click',function(){
sessionStorage.setItem('story','');
});
});
</script>

How to Display A Popup Only Once Per User How to Display A Popup Only Once Per User Reviewed by TechTubeHQ on November 01, 2021 Rating: 5

No comments:

Powered by Blogger.