0

jQuery(window).load() not working properly in IE, especially in IE 8 and below. I need to call one method after loading the window completely.

But in IE the window shows after executing the function given in jQuery(window).load() also.

.
.
.
.
</body>
<script language="javascript">
jQuery(window).load(function(){
    renderEditNView();
});
</script>
</html>

Even an alert within the load method shows before the window loads. How will I fix it?

Mahesh.D
  • 1,691
  • 2
  • 23
  • 49
skmaran.nr.iras
  • 8,152
  • 28
  • 81
  • 116

5 Answers5

2

try this I hope it works on your browser too

$(window)[0].onload = (function(){alert('done');});

javascript :

window.onload = (function(){alert('done');});

note: even your code is working on chrome and jQuery 1.9.1!

CME64
  • 1,673
  • 13
  • 24
1

Use any method call Inside $(function() :

<script type="text/javascript">
    $(function(){
       alert('Alert box after page Completely Ready');
       renderEditNView();
    });

    function renderEditNView(){
         alert('Render Edit and View after Page Competely ready');
    }
</script>
1

See document http://api.jquery.com/load-event/

In general, it is not necessary to wait for all images to be fully loaded. If code can be executed earlier, it is usually best to place it in a handler sent to the .ready() method.

commit
  • 4,777
  • 15
  • 43
  • 70
1

Try to put the script code inside the body tag (at the end for example). IE might be have some problems with that if the renderEditNView is changing the DOM...

See this question for more info

Community
  • 1
  • 1
Jonathan Naguin
  • 14,526
  • 6
  • 46
  • 75
0

I tested all of the responses offered and all of them is not working, I am trying to get the outerHeight using $("#element").outerHewight(); after the page is loaded and always is returning 0 because I need to know the height after to fill the data. What I tested is:

<script type="text/javascript">
   // it is no working
   window.onload = (function(){alert($("#myelement").outerHeight());});

   // It is no workking
   $(window)[0].onload = (function(){alert($("#myelement").outerHeight());});

</script>

If I am not mistaken, $("#myelement").outerHeight(), should return some value after the page is loaded, why is returning 0?

For this reason I think both pruposed option arent right.

I can not use pluggin.

I am using Internet Explorer 8. (I can not changhe of navigator)

I wrote in this question because it is quite similar what we are looking for.

david
  • 39
  • 2
  • 10