Link to home
Create AccountLog in
Avatar of sandshakimi
sandshakimiFlag for United States of America

asked on

Disable Modal Window After Initial Page Load ?

This code displays the Welcome modal window on page load on the Landing page, and also when the page is refreshed.

The Visitor only needs to see it once as they navigate the site and return back to the Landing page.

What's the code to have it viewed just once for the Visitor?

</noscript>
<script>
    $('#welcomeModal').modal('show');
	$("#file-3").fileinput({
		browseClass: "btn btn-warning  ",
		showUpload: true,
		showRemove: false,
		showCaption: false,
		
		fileType: "any"
	});
    $(".btn-warning").on('click', function() {
        if ($('#file-4').attr('disabled')) {
            $('#file-4').fileinput('enable');
        } else {
            $('#file-4').fileinput('disable');
        }
    });

	</script>
<noscript>

Open in new window

modal12.PNG
Avatar of Gary
Gary
Flag of Ireland image

Use sessions, you need session_start() on every page where you may be calling the modal.

<?php
session_start(); // start a session
...
...
<script>
<?php
// if the session is not set then show the modal
if (!isset($_SESSION['modal'])){
    echo "$('#welcomeModal').modal('show');";
}
$_SESSION['modal']=1; // create the session
?>
...

Open in new window

Avatar of sandshakimi

ASKER

Is there a benefit to do this serve side wth PHP, or should I also consider JavaScript?
Gary, can you explain the code.

So within the same browser session, the Visitor will return to the Landing page, but will not see the modal again? Which is the objective.
SOLUTION
Avatar of Gary
Gary
Flag of Ireland image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
You may want a longer-term memory of the cookie.  This article gives the general design pattern.  I think it could be adapted for a modal window, just as it is used for a "splash" page.
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_3314-How-to-Show-an-Introductory-Web-Page-Once-Using-PHP.html
Gary, so with this approach, on their next visit the User will not see the modal?

1) What if they clear their browser history prior to visiting a second time?

2) Or visit with a different browser on thier second visit?

3) Or view in phone, tablet first time, second time?
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER CERTIFIED SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.