html image javascript

execute function after complete page load

I am using following code to execute some statements after page load.

 <script type="text/javascript">
window.onload = function () {

But this code does not work properly. The function is called even if some images or elements are loading. What I want is to call the function the the page is loaded completely.