开发者

How to show a Prelaoder/Loading animation/gif/percentage while the included PHP page processes/loads?

I'm including a PHP script with in a main PHP page.

Help me "how to show a Preloader/loading animation or gif or swf or simply percentage of loading while the included PHP script processes & loads?" Here is the code snippet where I want to show the same (See the last line of code):

<body onLoad="document.forms.form1.from.focus()">
<font face="Calibri">
<table cellpadding="10">
   <form action="<?=$_SE开发者_JAVA百科RVER['PHP_SELF']?>" method="post" name="form1">
<tr>
<td width='25%'>
    <fieldset>
        <legend>Enter From & To Date</legend>
        <table border='0'>
        <tr>
            <td>From </td>
            <td><input type="text" name="from" /></td>
        </tr>
    </fieldset>
            <input type="submit" name="submit" value="Submit" />
</td>
</tr>
</form>
</table>
<?  
//Form submitted
if(isset($_POST['submit'])) 
{
    //No errors, process
    if(!@is_array($error)) 
    {  
 HERE IS WHERE I WANT THE LOADING TO TAKE PLACE
//HERE I INCLUDE THE SCRIPT

Also, if i can delay the display of the PHP script until it completes processing.


Put a <div> containing your loading screen right after the <body> (or at least before the time-consuming loading happens). At the very end (or after the long part which should be covered by the loading screen) add some JavaScript to hide/remove the div containing the loading screen.


This is my modified version of a script I got off the internet. Cant remember where I got it from sorry.

<html>
<head>
<script type="text/javascript">
function swapdiv() { 
    //Hide the loading div
    if (document.getElementById) { // DOM3 = IE5, NS6 
        document.getElementById('loadingdiv').style.display = 'none'; 
    } else { 
        if (document.layers) { // Netscape 4 
            document.loadingdiv.display = 'none'; 
        } else { // IE 4 
            document.all.loadingdiv.style.display = 'none'; 
        } 
    } 

    //Show the results div
    if (document.getElementById) { // DOM3 = IE5, NS6 
        document.getElementById('resultdiv').style.display = 'block'; 
    } else { 
        if (document.layers) { // Netscape 4 
            document.resultdiv.display = 'block'; 
        } else { // IE 4 
            document.all.resultdiv.style.display = 'block'; 
        } 
    } 

    window.onunload = null;
    return;
} 
</script>
</head>
<body>
<form name="form1">
</form>
<div id='loadingdiv' align='center'><img src='../images/loading.gif' alt='Loading...' title='Loading...' /></div>
<div id='resultdiv' style='display:none;'>
<!-- Do some html stuff here. This div block is hidden until the end of page load -->
<?php
    //Query database
    //Show results
?>
</div>
<script type='text/javascript'>
    //this is called after page loaded
    window.onload=swapdiv;
</script>
</body>
</html>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜