views:

170

answers:

1

Hi all,

i used sometimes a 'loading' method with the javascript onload & onunloadbody events.(www.restaurantebarocortico.com)

Now i'm learning jQuery, and i used the $(document).ready & $(window).unload to replace the old events, but the unload event isn't working correctly. Does anybody knows another method to call a function on unload? And, if needed, a method to break the unload and do some effect (, i will need this to put an effect showing the loading div on unload).

the flow of the loading div:

  • it appears on the top of everything (without effect) with an ajax-loader gif at the middle center.
  • when document is ready, hide it with jQuery function (slow effect)
  • when document/window is unloading, show it with jQuery function (slow effect again), and break for a while the event (or sleep the time of the effect).

Thanks and sorry my english :P José Moreira

+1  A: 

You cannot prevent an unload or beforeunload event. If you could, people would abuse it to make tabs unclosable.

Eli Grey
and can i make a unix sleep like function? with javascript or a function from jquery.
CuSS
yes, you have right, but, if you call alert(), it can 'pause' until it stops. right?
CuSS
You _can_ `alert()`, but you shouldn't. Also, there is no such thing as a sleep function in JavaScript that pauses the thread.
Eli Grey