0

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

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
cusspvz
  • 5,143
  • 7
  • 30
  • 45

1 Answers1

2

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

Eli Grey
  • 35,104
  • 14
  • 75
  • 93
  • and can i make a unix sleep like function? with javascript or a function from jquery. – cusspvz Jan 28 '10 at 11:19
  • yes, you have right, but, if you call alert(), it can 'pause' until it stops. right? – cusspvz Jan 28 '10 at 15:03
  • 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 Jan 28 '10 at 20:56