unload.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. define("dojo/_base/unload", ["./kernel", "./connect"], function(dojo, connect) {
  2. // module:
  3. // dojo/unload
  4. // summary:
  5. // This module contains the document and window unload detection API.
  6. var win = window;
  7. /*=====
  8. dojo.windowUnloaded = function(){
  9. // summary:
  10. // signal fired by impending window destruction. You may use
  11. // dojo.addOnWindowUnload() to register a listener for this
  12. // event. NOTE: if you wish to dojo.connect() to this method
  13. // to perform page/application cleanup, be aware that this
  14. // event WILL NOT fire if no handler has been registered with
  15. // dojo.addOnWindowUnload. This behavior started in Dojo 1.3.
  16. // Previous versions always triggered dojo.windowUnloaded. See
  17. // dojo.addOnWindowUnload for more info.
  18. };
  19. =====*/
  20. dojo.addOnWindowUnload = function(/*Object?|Function?*/obj, /*String|Function?*/functionName){
  21. // summary:
  22. // registers a function to be triggered when window.onunload
  23. // fires.
  24. // description:
  25. // The first time that addOnWindowUnload is called Dojo
  26. // will register a page listener to trigger your unload
  27. // handler with. Note that registering these handlers may
  28. // destory "fastback" page caching in browsers that support
  29. // it. Be careful trying to modify the DOM or access
  30. // JavaScript properties during this phase of page unloading:
  31. // they may not always be available. Consider
  32. // dojo.addOnUnload() if you need to modify the DOM or do
  33. // heavy JavaScript work since it fires at the eqivalent of
  34. // the page's "onbeforeunload" event.
  35. // example:
  36. // | dojo.addOnWindowUnload(functionPointer)
  37. // | dojo.addOnWindowUnload(object, "functionName");
  38. // | dojo.addOnWindowUnload(object, function(){ /* ... */});
  39. if (!dojo.windowUnloaded) {
  40. connect.connect(win, "unload", (dojo.windowUnloaded= function(){}));
  41. }
  42. connect.connect(win, "unload", obj, functionName);
  43. };
  44. dojo.addOnUnload = function(/*Object?|Function?*/obj, /*String|Function?*/functionName){
  45. // summary:
  46. // registers a function to be triggered when the page unloads.
  47. // description:
  48. // The first time that addOnUnload is called Dojo will
  49. // register a page listener to trigger your unload handler
  50. // with.
  51. //
  52. // In a browser enviroment, the functions will be triggered
  53. // during the window.onbeforeunload event. Be careful of doing
  54. // too much work in an unload handler. onbeforeunload can be
  55. // triggered if a link to download a file is clicked, or if
  56. // the link is a javascript: link. In these cases, the
  57. // onbeforeunload event fires, but the document is not
  58. // actually destroyed. So be careful about doing destructive
  59. // operations in a dojo.addOnUnload callback.
  60. //
  61. // Further note that calling dojo.addOnUnload will prevent
  62. // browsers from using a "fast back" cache to make page
  63. // loading via back button instantaneous.
  64. // example:
  65. // | dojo.addOnUnload(functionPointer)
  66. // | dojo.addOnUnload(object, "functionName")
  67. // | dojo.addOnUnload(object, function(){ /* ... */});
  68. connect.connect(win, "beforeunload", obj, functionName);
  69. };
  70. return {
  71. addOnWindowUnload: dojo.addOnWindowUnload,
  72. addOnUnload: dojo.addOnUnload
  73. };
  74. });