Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript How to display page content after javascript finishes.

  • This topic is empty.
Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #24834
    kolins
    Member

    Hi, is there a way to make a page to wait for a javascript to finish first before displaying page contents? Or to disable mouse clicks until javacripts finishes loading?

    #57606
    AshtonSanders
    Participant

    hmmm… are you loading the javascript file first (ie in your <head>)? I have had bad luck trying to get things to wait for javascript. =/

    #57625
    kolins
    Member

    Yes, it’s in the <head>. My goal is to prevent visitors from doing anything on the page until the javascript is done.

    #57627
    AshtonSanders
    Participant

    How long does it take the Javascript to run?

    I would say, people don’t like being "Unable to do anything" ever, so it’ll be pretty tough to accomplish.

    #57635
    Hugo
    Member

    Isn’t this the same idea as the ‘loading page’ topic earlier this month? Like some sort of HTML/CSS-absolute positioned overlay to be displayed first, and eventually removing it with javascript (which will be the very last action javascript performs, hence: js is finished).

    #57636
    Stack
    Member

    Unless you have some 5000+ line script or a buttload of intervals or timeouts your script already does run before the page content is loaded. provided the script is in the head at least.

    #57657
    kolins
    Member

    Yes, something like putting a transparent overlay, then automatically removing it in the end. How do you do that? Sorry, but i can’t find the post. :D

    #57669
    Stack
    Member

    just put a absolutely positioned div at the top of the page (below head but above all content) and give it a width and height of the full page so it covers everything then give it a high z-index. then at the very end of your script select that div and give it a display: none property

    #57647
    AshtonSanders
    Participant

    Right, you could do something like this:

    Code:
    #loadingscreen {
    position:absolute;
    top:0;
    bottom:0;
    left:0;
    right:0;
    z-index:30;
    background: #fff url(‘loadingimg.gif’) center center;
    }

    Make sure to have a loading image so people don’t get totally pissed about the white screen.

Viewing 9 posts - 1 through 9 (of 9 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.