You can set a variable in $_SESSION
and check if it was set at the time of showing the Preload, in the case of PHP would be something like this:
<?php
session_start();
if (empty($_SESSION['preload'])) {
$_SESSION['preload'] = true;
//código para mostrar o preload
}
?>
With JS you can do using cookie for example:
function setCookie(cname, cvalue, days) {
var d = new Date();
var expires;
if (days) {
d.setTime(d.getTime() + (days*24*60*60*1000));
expires = "expires="+ d.toUTCString();
}else {
expires = "";
}
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i = 0; i <ca.length; i++) {
var c = ca[i];
while (c.charAt(0)==' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length,c.length);
}
}
return "";
}
function checkPreload() {
var preload = getCookie("preload");
if (preload == "") {
console.log("mostrar preload");
setCookie("preload", 1, 1);
} else {
console.log("já mostrou o preload");
}
}
checkPreload();
I don’t know much about PHP, how I would mount the PHP code in my html, once I use a div, another thing with a cookie would be ideal to save the cookie until the browser remains.
– user60953
Right, you could be at the event
onunload
delete the cookie– fernandoandrade
I couldn’t even assemble, could you give me an example of what the code would be like?
– user60953
You can set the cookie without the expiration date, in which case it will be removed at the end of the browser session when it is closed. I changed the function to allow you to do this, then you use
setCookie('preload', 1)
– fernandoandrade
Fernando without wanting to abuse you can give me a contact so I can resolve this issue?
– user60953
@Renato which your email?
– fernandoandrade
[email protected] @fernandoandrade
– user60953