最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Load splash screen only once at start in php - Stack Overflow

programmeradmin0浏览0评论

I have already created a splash screen using jquery's fadeOut option. It is working fine but the problem is the screen is loading every time I click to go to next page. I need splash screen only at startup. I think I need to use session or something but I am not able to find the solution. I am using following script.

 $(document).ready(function () {
 $("#splashscreen").click(function () {
    $("#splashscreen").fadeOut(2000); 
 });
 });

I have already created a splash screen using jquery's fadeOut option. It is working fine but the problem is the screen is loading every time I click to go to next page. I need splash screen only at startup. I think I need to use session or something but I am not able to find the solution. I am using following script.

 $(document).ready(function () {
 $("#splashscreen").click(function () {
    $("#splashscreen").fadeOut(2000); 
 });
 });
Share Improve this question edited Jul 11, 2017 at 15:49 Vadim Kotov 8,2848 gold badges50 silver badges63 bronze badges asked Aug 25, 2015 at 12:10 get_codingget_coding 271 silver badge10 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 5

This should work:

$(document).ready(function () {
    if( $.cookie('splashscreen') == null ) { // Here you are checking if cookie is existing if not you are showing a splash screen and set a cookie
        $("#splashscreen").fadeIn();
        $.cookie("splashscreen", 1, { expires : 10 }); // cookie is valid for 10 days
    }
    $("#splashscreen").click(function () {
        $("#splashscreen").fadeOut(2000); 
    });
});

You can set cookie and check for it when page refreshes. I suggest you to use library like this:

https://github./js-cookie/js-cookie

One option is to handle this in PHP, but you also can use the local storage in JS. Here is a related Topic: How to set session variable in jquery?

Yes, you can use a session for this. on the first line of your code add <?php session_start();

Now, later in your code, you can do:

if(!$_SESSION['splash'])
{
    $_SESSION['splash'] = true;

    //echo your splash code here
}
发布评论

评论列表(0)

  1. 暂无评论