So, I solved the problem myself. But, anyway, thanks to @ prabeen-giri, who helped me think correctly. First, I need to explain the preloader mechanism. Just look at the CSS:
position: fixed; display: block; top: 0; right: 0; left: 0; bottom: 0; background-repeat: no-repeat; background-position:center; center; background-size: auto auto; background-image: url(../images/preload.png); background-color:#000; z-index:99;
So, your preloader is just an image or something else that spans all windows and fades out smoothly (by jQuery) when all the content is loaded.
<div id="preloader" class="preloader"></div>
And here is the script:
<script type="text/javascript"> $(window).load(function() { $("#preloader").delay(700).fadeOut("slow");}); </script>
To solve my problem and show the preloader only once when entering the site through a domain name, we need to use cookies. There are 2 helper cookie functions (from Quirksmode ):
function createCookie(name,value,days) { if (days) { var date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); var expires = "; expires="+date.toGMTString(); } else var expires = ""; document.cookie = name+"="+value+expires+"; path=/"; } function readCookie(name) { var nameEQ = name + "="; 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,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); } return null; }
So, we need to enter our own cookie in order to create conditions for the script to run. Initially, our created cookie is null , and this equality will be a condition for running the script. After that, we set the cookie to some value so as not to start jQuery again. Here is the code:
<script type="text/javascript"> $(window).load(function() { if (readCookie('referer') == null){ $("#preloader").delay(700).fadeOut("slow");} createCookie('referer',1,0); }); </script>
But how to remove our preview and background after page refresh? Because we just turned off jQuery fadeOut proccess by our conditions. The picture and the black background save our window and do not disappear ...
Create a new condition and put it in
<script> if (readCookie('referer') == null) { document.write("<style>.preloader {background-image: url(../images/preload.png); background-color:#000; z-index:99;}</style>"); } </script>
Under this we set our image, z-index and background to the preloader class. Our cookie is null only when the user enters the site through the domain name OR cleared his cookie and refreshed the page (which seems unlikely). And if the cookie is 1 , as we set above, our preloader will appear, but without a picture and background, and our jQuery fadeOut will not start either! So, my problem is solved the way I wanted, the preloader will appear only once. Thanks again @ prabeen-giri!