Solved

Disable Modal Window After Initial Page Load ?

Posted on 2014-11-26
8
226 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 110

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 110

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

679 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