Advertisement
Guest User

Untitled

a guest
Apr 17th, 2014
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. function onloadPreventer(fun) {
  2. if (window.location.hash != "#loaded") {
  3. //alert(window.location.hash);
  4. window.location = window.location + "#loaded";
  5. //alert(window.location.hash);
  6. fun;
  7. };
  8. };
  9.  
  10. <body onload="onloadPreventer(anotherFunction(arg))">
  11.  
  12. function foo(){ /* ... */ } /* does NOT call foo */
  13. function bar(){ /* ... */ } /* does NOT call bar */
  14. foo; /* does NOT call foo */
  15. foo(arg); /* DOES call foo with arg as argument */
  16. foo(bar); /* does NOT call bar, and DOES call foo with bar as argument */
  17. foo(bar(arg)); /* DOES call bar with argument arg, and DOES call foo
  18. with the returned value of bar as argument */
  19.  
  20. function onloadPreventer(fun) {
  21. if (location.hash !== (location.hash = "#loaded")) {
  22. fun(); // DOES call fun
  23. }
  24. }
  25.  
  26. <body onload="onloadPreventer(
  27. function(){anotherFunction(arg);} /* does NOT call anotherFunction */
  28. )">
  29.  
  30. function fun() {
  31. anotherFunction(arg);
  32. }
  33. document.body.onload = function onloadPreventer() {
  34. if (location.hash !== (location.hash = "#loaded")) {
  35. fun(); // DOES call fun
  36. }
  37. };
  38.  
  39. <html><head>
  40. <script type="text/javascript">
  41. var callWhenNoHash = function() {
  42. console.log('called');
  43. };
  44. window.onload = function() {
  45. if (window.location.hash != '#hash') {
  46. callWhenNoHash();
  47. }
  48. };
  49. </script></head>
  50. <body><a href="test2.html">test2</a></body>
  51. </html>
  52.  
  53. <html><head></head><body>
  54. <a href="test1.html#hash">test2</a>
  55. </body></html>
  56.  
  57. $(window).load(function(){
  58. var load = "#loaded";
  59. if (window.location.hash != load) {
  60. window.location = window.location + load;
  61. document.write(load);
  62. };
  63. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement