Solved

Disable Modal Window After Initial Page Load ?

Posted on 2014-11-26
8
223 Views
Last Modified: 2015-01-12
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
0
Comment
Question by:sandshakimi
  • 3
  • 3
  • 2
8 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 40468268
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

0
 

Author Comment

by:sandshakimi
ID: 40468359
Is there a benefit to do this serve side wth PHP, or should I also consider JavaScript?
0
 

Author Comment

by:sandshakimi
ID: 40468368
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.
0
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 
LVL 58

Assisted Solution

by:Gary
Gary earned 334 total points
ID: 40469284
not see the modal again
Correct, in any visit they will only see it once

You can also use a cookie or local storage, this makes it a bit more complicated if you still want to show the modal on their next visit - so the session is the easiest way
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 40469772
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.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_3314-How-to-Show-an-Introductory-Web-Page-Once-Using-PHP.html
0
 

Author Comment

by:sandshakimi
ID: 40470025
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?
0
 
LVL 109

Assisted Solution

by:Ray Paseur
Ray Paseur earned 166 total points
ID: 40470351
PHP sessions are short-term storage.  They are (almost always) cookie-based, and cookies are device+browser specific.

1) What if they clear their browser history prior to visiting a second time?
If the client removes the cookie, the browser cannot send the cookie to the server, therefore the server has lost its "stateful" information and will not know that the client has visited before.

2) Or visit with a different browser on their second visit?
Each browser and each device has its own "cookie jar" and if the browser does not send the cookie with the request, the server will not receive the cookie and will not know that the client has visited before.

3) Or view in phone, tablet first time, second time?
Each device and each browser has its own "cookie jar" and if the browser does not send the cookie with the request, the server will not receive the cookie and will not know that the client has visited before.

4) Or just sits there doing nothing for a while?
PHP sessions have a "garbage collection" algorithm that causes PHP to clean up unused session data after a period of time.  It's a complicated algorithm, but you can research it on php.net to see when it may get invoked (some installation and configuration parameters are involved) and whether it's useful for your application design

5) Or closes the browser and then starts it up again?
PHP Session cookies are normally set with a lifetime of zero, meaning that they disappear when the browser is closed.  So if you're reliant on sessions, your client will lose the session cookie when they close the browser and when they reopen the browser and come back to your site the browser will not be able to send a cookie, hence they will not be able to renew a session.

There are some other long-term persistent client data stores that you may want to consider.  Browser implementation and human acceptance is uneven.
http://www.sitepoint.com/html5-browser-storage-past-present-future/
0
 
LVL 58

Accepted Solution

by:
Gary earned 334 total points
ID: 40470398
No, they will see the modal on the next visit
If they use a different browser or device then they will see it initially again.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
HTML Anchor Link Problem 3 36
AJAX, If No returns don't let the AJAX Call run again 2 21
Ajax and PHP 9 30
Showing multiple maps using PHP and Google Maps 8 20
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question