when the page is ready everything is simple: $ (document) .ready (); And if I need to know when the page is not ready?

I want to do: when the page is already loaded (!), When I click the link, issue a download gif. I need to know when the page has not changed yet, but the download has gone another ...

All the links to make an event I think is silly ...

  • Make an event for the body that starts spinning the spinner. - ReinRaus

1 answer 1

It's not entirely clear what you want to do.

You can find out when the current page started unloading using the window.onunload event. However, as soon as the next page starts loading, the browser will destroy the previous one along with all the icons, elements and code, and your download icon will disappear. In fact, in this way you will display it for a split second.

To implement what you want , you need to load pages with AJAX without destroying the current page . If you load pages by links using AJAX (i.e., a javascript request), you can do the following.

  1. The user clicks the link, your JavaScript-handler of this event is called.
  2. You show the download icon , then start the download itself using AJAX (specifically in jQuery - $.get , $.post , $.ajax and the like).
  3. When the loading is completed in the handler function, you, among other things, remove the loading icon and replace the old content of the page with the newly received one.

A crutch, but it's better to realize nothing yet.

  • Yes, I need to that split second! I'm here to experiment a bit and I probably need window.onunload - Mike
  • and where can I read about window.onunload? If there is a link. I will be very grateful - Mike
  • one
    @myvzar, for example, here . There is also a window.onbeforeunload event, but it is not guaranteed to be cross-browser. - khaos