Add just under the page <body> tag – Normal
<body>
  <!------------------------------------->
  <!---- PAGE LOADING COVER ELEMENT ----->
  <!------------------------------------->
  <div id="page_loading_cover"></div>
  <div id="page_loading_cover_animated_icon"></div>
  <script>
    /* Remove greyed loading page cover once page has finished loading */
      //$(window).on('load', function() {      //Don't use this as it won't trigger if user presses their back button
      $(window).on('pageshow', function() {    //'pageshow' triggers for page load and back button back to page
       $("#page_loading_cover").hide();
      page_loading_cover.style.visibility = "hidden" ;
      page_loading_cover_animated_icon.style.visibility = "hidden" ;
    });

    /* Turn on greyed loading page cover */
    function DisablePageUntilReloaded() {
      $("#page_loading_cover").show();
      page_loading_cover.style.visibility = "visible" ;
      page_loading_cover_animated_icon.style.visibility = "visible" ;
    }
  </script>
Add just under the page <body> tag – WordPress

(Same but needs the ‘$’ changed to ‘jQuery’ or you get “TypeError: $ is not a function” console errors)

<body>
  <!------------------------------------->
  <!---- PAGE LOADING COVER ELEMENT ----->
  <!------------------------------------->
  <div id="page_loading_cover"></div>
  <div id="page_loading_cover_animated_icon"></div>
  <script>
    /* Remove greyed loading page cover once page has finished loading */
    jQuery(window).on('load', function() {
       jQuery("#page_loading_cover").hide();
      page_loading_cover.style.visibility = "hidden" ;
      page_loading_cover_animated_icon.style.visibility = "hidden" ;
    });

    /* Turn on greyed loading page cover */
    function DisablePageUntilReloaded() {
      jQuery("#page_loading_cover").show();
      page_loading_cover.style.visibility = "visible" ;
      page_loading_cover_animated_icon.style.visibility = "visible" ;
    }
  </script>
Create a style for it
/*----- PAGE LOADING COVER ELEMENT -----*/
#page_loading_cover {
  position: fixed;
  height: 100%;
  width: 100%;
  top:0;
  left: 0;
  background: #000;
  opacity: 0.5;
  z-index:9999;
  visibility: hidden;  /*Include this so element will only be shown when DisablePageUntilReloaded() is called*/
}

/*Spinning icon*/
#page_loading_cover_animated_icon {
  border: 12px solid #f3f3f3;
  border-radius: 50%;
  border-top: 12px solid #3498db;
  width: 80px;
  height: 80px;
  -webkit-animation: animated_icon_spin 2s linear infinite; /* Safari */
  animation: animated_icon_spin 2s linear infinite;
  
  position: fixed;
  top: 50%;
  left: 50%;
  margin-top: -40px;
  margin-left: -40px;
  z-index:9999;
  visibility: hidden;  /*Include this so element will only be shown when DisablePageUntilReloaded() is called*/
}
/* Safari */
@-webkit-keyframes animated_icon_spin {
  0% { -webkit-transform: rotate(0deg); }
  100% { -webkit-transform: rotate(360deg); }
}

@keyframes animated_icon_spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}
For any form submit you want to trigger it use onsubmit
<form id="my_form" onsubmit="return DisablePageUntilReloaded()" action="\my_page.php" method="POST">

If you have any onchange submit form elements you will need to call the function separately as onchange .submit won’t trigger it:

<input type="checkbox" name="MyCheckbox" value="1" onchange="DisablePageUntilReloaded(); my_form.submit();" >
For any html link you want to trigger it use onclick
<a href="/my_page.php" onclick="DisablePageUntilReloaded()" >Click me</a>
UK Electronic Designer
USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.

Comments

Your email address will not be published.