Thanks but why the need for this script in the body?

Code:
<script type="text/javascript">

        window.onload = function() {

            openindex();

        };

    </script>
What I am seeing online does not have a script tag in the body, only the

onLoad="openindex()"

so what doesn't that work please?