Dynamically add and remove text on a page

Discussion in 'PHP' started by adacprogramming, Jan 7, 2011.

  1. #1
    I don't do much PHP I'm trying to accomplish something I do in C#.

    I want to have a small piece of text load as soon as the page loads, at that point the code starts working, this can take up to a minute. When finished I want the text to go away (or possibly be replaced.)

    Is there a "Label" control in php so that when the page first starts to display this label will show? is so, is there a way I can then make it invisible in the code?

    as an example when you go to http://websiteanalysis.topwebsitetips.com/results/affiliatemarketerguide.com. You will see the text "It can take up to 1 minute to collect the Analysis Information" when the page first loads, with nothing else on the page. When the page completes in a minute or so, I want that text to go away.
     
    adacprogramming, Jan 7, 2011 IP
  2. shofstetter

    shofstetter Well-Known Member

    Messages:
    178
    Likes Received:
    7
    Best Answers:
    1
    Trophy Points:
    120
    #2
    shofstetter, Jan 7, 2011 IP
  3. adacprogramming

    adacprogramming Well-Known Member

    Messages:
    1,615
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    125
    #3
    interesting idea, but what code will make the frame go away. I suppose I could set it to a 0 height and width, but there isn't an attribute that makes it invisible.

    I don't want any of the data in an iframe, only the text that will eventually go away.
     
    adacprogramming, Jan 7, 2011 IP
  4. shofstetter

    shofstetter Well-Known Member

    Messages:
    178
    Likes Received:
    7
    Best Answers:
    1
    Trophy Points:
    120
    #4
    You can load the data in an iframe with the width and height set to 0 and set the style to display:none, when it has finished loading use the .innerHTML to replace the body of the page.

    example:
    
    <html>
    <head>
    <script type="text/javascript">
    function swapme(){
    	document.body.innerHTML = window.frames['test'].document.body.innerHTML
    }
    
    </script>
    </head>
    
    <body>
    <h2>Please wait while we load your results</h2>
    <iframe id="test" name="test" src="test.html" onload="swapme();" width="0" height="0" style="display:none;"></iframe>
    </body>
    </html>
    
    Code (markup):
     
    shofstetter, Jan 7, 2011 IP
  5. adacprogramming

    adacprogramming Well-Known Member

    Messages:
    1,615
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    125
    #5
    I've been working on a disappear version. but can't seem to get it to work. any idea why?

    Code in head
    <script type="text/javascript">
        function remove()
        {       
           // Check if loading is complete
          if ( iframe.document.readyState == 'complete' ) {
              // The loading is complete, call the function we want executed once the iframe is loaded
              var elem = document.getElementById('waitIframe');
              var old = (elem.parentNode).removeChild(elem);
              return;
           }
    
           // If we are here, it is not loaded. Set things up so we check   the status again in 100 milliseconds
           window.setTimeout('remove();', 100);    
            
        }
    </script>
    Code (markup):

    Code in body
    <iframe id="waitIframe" onload="remove();" width="450px" height="30px" scrolling="no" src="pleasewait.htm"></iframe>
    Code (markup):
     
    adacprogramming, Jan 7, 2011 IP
  6. shofstetter

    shofstetter Well-Known Member

    Messages:
    178
    Likes Received:
    7
    Best Answers:
    1
    Trophy Points:
    120
    #6
    It doesn't work backwards. The only way to display the message is to have it already present, and then load your data. It won't work the other way around because the script won't run until the page has loaded. And php won't send the page until it has finished.
     
    shofstetter, Jan 7, 2011 IP
  7. adacprogramming

    adacprogramming Well-Known Member

    Messages:
    1,615
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    125
    #7
    ok
    I'm working on setting up a page with the code you put in the thread
     
    adacprogramming, Jan 7, 2011 IP