Solved

Disable Modal Window After Initial Page Load ?

Posted on 2014-11-26
8
219 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

785 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