Jump to content

PHP Help Required


worth2talk

Recommended Posts

Hi PHP Guru,

  I am a newbie and looking for help from you. Okay..lets come to the problem...

I wrote a php function which executes some Java scripts as below (for example) :

 

// index.php

 

<body>

<?php

  include("func.php");

display();

?>

</body>

---------------------------------------

// func.php

 

<?php

function display() {

echo' <div class="dispMain">

<script type="text/javascript">

        // Some Javascript code ...

</script>

</div>';

}

?>

 

Well, everything is working fine. What i want is to make sure display() function in index.php is called only when the entire page is loaded... how can i do that ? Is it possible to provide some delay such that display() is called only after that delay ?

 

Fast response will be appreciated ..!!

 

Thanks in Advance.

Link to comment
Share on other sites

Well, it would be easy. However website took some time to display main content. It basically fetches data from other resource dynamically which may cause some delay. And the problem is when site is opened, javascript inside display() is executed before other content. so i just want to add some delay in function call.

Link to comment
Share on other sites

Sleep() basically delay the execution of all the code written after the sleep(). It doesn't useful when you want to delay the particular function.

 

Let me be more specific towards my problem. Consider the same code snippet:

 

// index.php

<body>
   <?php
        include("func.php");
   ?>

  <!-- Some HTML -1 code goes here -->

   <?php
        display();
   ?>      

  <!-- 
   Some HTML - 2 code goes here.
   This code should not be delayed because of delay in display()
   -->

</body>

 

// func.php

<?php
function display() {
   echo' 
     <div class="dispMain">      
           <script type="text/javascript">
               // Some Javascript code ...
           </script>
     </div>';
}
?>

 

I want to delay the display() routine, such that the javascript inside display() will execute after few seconds. However "HTML - 2" will not get delayed. So the page display sequence should be as below:

 

1. HTML - 1 code executes

2. HTML - 2 code executes

3. display() (due to delay executed after HTML-2 code)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.