How can I execute a specific code whenerver I change to a new page?

Viewed 30

I'm trying to show a loading overlay everytime I change to a page.

For example: If I change to the basket, a category, a product or any other page, a loading circle will appear on it. Pretty much like the loadingcircle of the Browser.

Is there an easy way to run the code for every change of a page?

I'm using .net Framework with a MVC Struktur and a Layout page which loads all necessary views.

1 Answers

If you want to execute such a code prepare the item you want to show and hide it with a class that contains "display:none". After that, insert this code into the scripts tag on the bottom of the layout:

  window.onbeforeunload = confirmExit;
  function confirmExit()
  {
    $("#loadingItem").removeClass("hidden");
  } 

onbeforeunload triggers everytime you change a site and you can execute whatever code you want.

Related