admin管理员组文章数量:1430527
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
4 Answers
Reset to default 5This 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
}
本文标签: javascriptLoad splash screen only once at start in phpStack Overflow
版权声明:本文标题:javascript - Load splash screen only once at start in php - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745505084a2661207.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论