satinez satinez - 9 months ago 49
Javascript Question

Run JS SetTimeout function only once per domain

I've implemented a Splash Screen in JQuery on my WordPress Site on Document ready.

setTimeout(function() {
}, 3000);

Ok, the Overlay fades out after 3 seconds. But if I click on a menu button, the whole page reloads and the function
repeats because its on the document ready.

How can I set this only for one time per Domain without using complicated code?


What you will have to do is implement cookies or something alike

I would suggest which is my own library but there are other like its so you can pick one.

The point is to set a flag or something in a cookie or session that says that you already done the action you want.


  // <script .... .. inclode my cookies library

  setTimeout(function() {
    var overlayFlag = $.fn.myCookie({cName: "overlayFlag"});
    if (!overlayFlag) {
      $.fn.myCookie( {cName : "overlayFlag", cVal : true} );
  }, 3000);

Something along these lines, there are other solutions .. this seemed a simple.