Solved

Disable Modal Window After Initial Page Load ?

Posted on 2014-11-26
8
208 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
Comment Utility
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
Comment Utility
Is there a benefit to do this serve side wth PHP, or should I also consider JavaScript?
0
 

Author Comment

by:sandshakimi
Comment Utility
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
 
LVL 58

Assisted Solution

by:Gary
Gary earned 334 total points
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
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
Comment Utility
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 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 166 total points
Comment Utility
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
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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 count occurrences of each item in an array.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now