On my site, a number of operations can take a long time.
When I know that it takes some time to load a page, I would like to display a progress indicator while the page is loading.
Ideally, I would like to say something like:
$("#dialog").show("progress.php");
and have this overlay on top of the loaded page (disappears after the operation is completed).
Encoding a progress bar and displaying progress is not a problem; the problem is getting a progress bar to pop up while the page is loading. I am trying to use jQuery dialogs for this, but they only appear after the page is already loaded.
This should be a common problem, but I'm not good enough in JavaScript to learn how to do this.
Here is a simple example to illustrate the problem. The code below does not display a dialog box up to a 20 second pause. I tried in Chrome and Firefox. Actually, I donβt even see the text "Please wait ...".
Here is the code I'm using:
<html> <head> <link type="text/css" href="http://jqueryui.com/latest/themes/base/ui.all.css" rel="stylesheet" /> <script type="text/javascript" src="http://jqueryui.com/latest/jquery-1.3.2.js"></script> <script type="text/javascript" src="http://jqueryui.com/latest/ui/ui.core.js"></script> <script type="text/javascript" src="http://jqueryui.com/latest/ui/ui.dialog.js"></script> </head> <body> <div id="please-wait">My Dialog</div> <script type="text/javascript"> $("#please-wait").dialog(); </script> <?php flush(); echo "Waiting..."; sleep(20); ?> </body> </html>
javascript jquery jquery-ui progress-bar
Oleg Barshay
source share