-1

I want to run some code after everything on the target page is done loading AND rendering. It was suggested to me to use the Window.load function and it is working perfectly in Firefox and Chrome. I just can't get it to work in IE. Is there another way of doing this?

Edit: Ok so here is what I have:

appAPI.ready(function($) {
if (appAPI.isMatchPages("192.168.1.156/test/*")) 
{
    $("body").css("display","none");

    if ( $('.welcome p').text().indexOf("user") >= 0 )
    {
        if ( $('h1').text().indexOf("header") >= 0 )
        {
            //alert("Found data");
            $('td:contains("testdata")').text("newdata");
        }
    }

    $(window).load(function () {
        $("body").css("display","block");
    });
}
});

Basically before there was code flickering, I could see the data being changed as the page loaded so I asked for some advice and the solution I got was to set the body style to display:none and use window.load to set it back to block once everything is loaded. This works perfectly in Firefox and Chrome but not in IE. The actual code that changes the data works in IE tho.

Chris
  • 141
  • 10

1 Answers1

1

You should have no issue with this in IE, I use it frequently when I need to ensure all resources have been downloaded:

$( window ).load(function() {
  // Run code
});

"Run a function when the page is fully loaded including graphics." ref: http://api.jquery.com/load-event/

Mister Epic
  • 16,295
  • 13
  • 76
  • 147
  • I have no idea why would you post an answer like that...which is not even an answer :P – Ani Dec 22 '13 at 18:13
  • @Ani: Why is it not an answer? It demonstrates exactly how to use the `load` even on `window` with jQuery (the question is tagged `jquery`), and it refers to the documentation. It's rather more of an answer than the question deserves, frankly. – T.J. Crowder Dec 22 '13 at 18:14
  • 1
    Because i don't think OP is asking for syntax. He said it works fine in other browser, which makes me thinks syntax is correct. – Ani Dec 22 '13 at 18:16
  • @Ani: Meh, okay. With questions as vague and incomplete as this one, I tend to discount claims like that. The number of times I've seen "it works in X" when there was no chance whatsoever that it worked in X... – T.J. Crowder Dec 22 '13 at 18:17
  • Not necessarily, Ani. IE, especially older versions, played loosy-goosy with the spec, and the benefit of leveraging jQuery in the fashion I indicated above is the framework very adeptly manages the vagaries between all the different browsers and versions. If the code I posted above is used, the OP will have no issue, even down to IE7. – Mister Epic Dec 22 '13 at 18:19
  • 1
    @T.J.Crowder Exactly my point. When the question is incomplete why would you write an answer like that. – Ani Dec 22 '13 at 18:19
  • I suppose I could have voted to close the question as well, but it's three days before Xmas, I'm stuck in an airport for the foreseeable future, and I'm in the holiday spirit :) – Mister Epic Dec 22 '13 at 18:20
  • No offense to anyone. Happy Holidays !!!..Just trying to help someone who will stumble upon this question for an answer – Ani Dec 22 '13 at 18:22