Solved

Disable Modal Window After Initial Page Load ?

Posted on 2014-11-26
8
216 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 108

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 108

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

863 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

19 Experts available now in Live!

Get 1:1 Help Now