0

I've tried googling but I'm having trouble expressing what i'm asking.

There seem to be different ways to trigger events and I was wondering if there's a difference between them.

On way is for example:

window.onload=function(){headerAdjustWidth();thumbsArrange();checkHash();}
window.onscroll=function(){windowScrollStore();}
window.onresize=function(){headerAdjustWidth();thumbsArrange();windowScrollAdjust();showExpanded(false);}
window.onkeydown=function(){checkKeyboard();}

And another way is

<body onKeyDown="checkKeyboard();" onLoad="headerAdjustWidth();thumbsArrange();checkHash();" onScroll="windowScrollStore();" onResize="headerAdjustWidth();thumbsArrange();windowScrollAdjust();showExpanded(false);">

Are there any pros/cons to each so far?

The other thing is for the onload functions, is there any reason why I should/shouldn't just put them straight in a <script> thing? e.g:

<script type="text/javascript">
  headerAdjustWidth();
  thumbsArrange();
  checkHash();
</script>

Finally, is there any reason why I should do window.onscroll=function(){windowScrollStore();} rather than window.onscroll=windowScrollStore?

l0k
  • 43
  • 1
  • 6
  • One of the main difference between using `onload` and a ` – Paolo Moretti Jun 13 '14 at 17:46
  • @PaoloMoretti Thank you, I've gone with putting it all in the – l0k Jun 13 '14 at 21:56

1 Answers1

0

In my point of view, it is much better to not include calls of javascript within HTML because this makes several building steps complicated such as OFFUSCATION of code.

I highly recommand to use the solution to keep javascript within javascript.

Concerning onload function, as described abode, I function on scripts as it simplificates building process.

aorfevre
  • 5,034
  • 3
  • 21
  • 51