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
  • 22
  • 46
Sarika.S
  • 7,366
  • 28
  • 76
  • 108
  • `document.ready` not good for you? – Ivan Chernykh Jun 28 '13 at 10:53
  • 1
    try to use `$(document).ready` instead of `jQuery(window).load` and see if it helps – Ivan Chernykh Jun 28 '13 at 10:54
  • @Cherniv: it will not help. it comes before the page load. I checked with an alert. – Sarika.S Jun 28 '13 at 10:58
  • what jQuery version in use? – Ivan Chernykh Jun 28 '13 at 10:58
  • 1
    if you tried `$(document).ready(function(){ /* code */});` and you can call any dom element from within the /*code*/ in the page then it is working properly, but you might have a different expectation for the functionality in your mind ,, it is not for after loading the contetns data, but rather the document's elements, or the window it self if it is shown in case of `$(window).ready..` – CME64 Jun 28 '13 at 11:13
  • I am using this https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js – Sarika.S Jun 28 '13 at 11:22
  • even with 1.9 it will act the same way – CME64 Jun 28 '13 at 11:26

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,663
  • 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,707
  • 14
  • 41
  • 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,036
  • 5
  • 45
  • 74
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