1

The normal flow is to have JavaScript manipulate the DOM. For example, I have a callback from a transaction executeSql on an openDatabase. The callback manipulates the DOM to add the result into a div.

But I have a special case where the page has to load correctly in toto. Yes, that's right - I used the phrase in toto.

Q: Is there a way for JavaScript to pause the page load until call the callbacks have called back?

I'm thinking I will have to use document.write instead of $('body').append().

3
  • Ignoring "in toto" which should get you banned, I'm unclear on the order. You want to wait for the HTML/page resources to be loaded before running javascript? Or you need to wait for something server side to finish? Commented Oct 20, 2011 at 17:11
  • Not sure quite what you're asking here. Are you trying not to display any data until all ajax calls are completed? Is your content in the HTML Page, or are you writing it all with JS dynamically? Commented Oct 20, 2011 at 17:15
  • When the executeSql gets called back, I populate a div. But my requirements are that the div be populated correctly when the page loads rather than after the page loads, which is when the callback occurs. Commented Oct 20, 2011 at 17:30

1 Answer 1

5

It sounds as if you are making a callback, initiated when the page load begins, but you don't want the page to display until the callback is complete.

Whatever the exact situation may be, the answer seems simple.

If you don't want a page to load before some event finishes, then do it synchronously on the server instead of starting it asynchronously on the client. Then you won't actually serve anything until it's done, and, hence, nothing will appear.

If for some reason this is not possible, then render all your content "hidden" and show it when the callback finishes.

Sign up to request clarification or add additional context in comments.

3 Comments

jamietre, thanks for that. The special case that I'm referring to is a bluetooth device that is reading the html output and displaying a certain id. The problem is that if JavaScript changes the text inside the identified element, then it's too late for the bluetooth device to see the change.
The client requires the application to run locally, so can't do it synchronously on the server.
I am not sure what limitations this device might have, but can you just do that latter idea, and render it as "display:none" initially, and show it from script whenever you are ready? At the end of the day there's no way to "pause" page loading - you can either cause your content not be delivered until you are ready (from the server), or you can deliver it in a way that does not render, and then render it when you're ready. Using "display:none" is the simplest way to do the latter, though you could also encode it and pass as JSON data or something, but I can't imagine why you'd need that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.