Guest User

Untitled

a guest
Jun 18th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. // DOMContentLoaded – the browser fully loaded HTML, and the DOM tree is built, but external resources like pictures <img> and stylesheets may be not yet loaded.
  2. document.addEventListener("DOMContentLoaded", function(e) {
  3. console.log(e);
  4. console.log("DOMcontentLoaded");
  5. });
  6.  
  7. // load – the browser loaded all resources(images, styles etc).
  8. window.addEventListener("load", function(e) {
  9. console.log(e);
  10. console.log("load");
  11. });
  12. // alternative
  13. // window.onload = function() {
  14. // console.log("load");
  15. // };
  16.  
  17. // event is fired when the window, the document and its resources are about to be unloaded
  18. // There's a lot of inconsistence between browsers and versions, some might not show the message returned or even don't show the dialog box at all
  19. window.addEventListener("beforeunload", function(e) {
  20. console.log(e);
  21. var confirmationMessage = "Leave? Are you sure?";
  22. e.returnValue = confirmationMessage; // Gecko, Trident, Chrome 34+
  23. return confirmationMessage; // Gecko, WebKit, Chrome <34
  24. });
  25. // alternative
  26. // window.onbeforeunload = function(e) {
  27. // return "Leave? Are you sure?";
  28. // };
  29.  
  30. // onunload - when a visitor leaves the page, fired after beforeunload
  31. window.addEventListener("unload", function(e) {
  32. console.log(e);
  33. console.log("unload");
  34. });
  35. // alternative
  36. // window.onunload = function() {
  37. // console.log("unload");
  38. // };
Add Comment
Please, Sign In to add comment