www.webdeveloper.com
Results 1 to 9 of 9

Thread: Auto refresh html - alternate pdf files

  1. #1
    Join Date
    Feb 2014
    Posts
    6

    Auto refresh html - alternate pdf files

    Hi,
    I have developed a report that is now on display on a separate computer in the middle of my office. This report changes frequent, so to display it, I wrote the following htm. It is not pretty, but it works.

    [html]
    <HTML>
    <HEAD>
    <TITLE>Delivery Schedule</TITLE>
    <META HTTP-EQUIV="refresh" CONTENT="600">
    </HEAD>
    <BODY>
    <iframe src="\\SERVER-NATBIO\Distribution\LOG\Uncontrolled\Delivery Schedule.pdf" width="100%" height="100%" FRAMEBORDER="0" MARGINWIDTH="0" MARGINHEIGHT="0" SCROLLING="no"></IFRAME>
    </BODY>
    </HTML>
    [\html]

    Now I have been asked to display another pdf report as well. I was wondering if it is possible to modify this code so that on each refresh, the html page will load a different file. The user looking at it would see something like this:
    start - file 1 is displayed
    5mins later - file 2 is displayed
    5mins later - file 1 is displayed again
    5mins later - file 2 is displayed again

    I haven't done much html, but my engineering logic would suggest something like the following should work, I just don't know how to do it in html:

    Set switch = first
    IF (switch = first, load file 1, set switch = second)
    ELSE (load file 2, set switch = first)
    End
    Refresh after 5min

    Thanks in advance!

  2. #2
    Join Date
    Jan 2014
    Location
    Boston, Massachusetts
    Posts
    66
    Why not just put the two reports in two iframes?

  3. #3
    Join Date
    Feb 2014
    Location
    Managua, Nicaragua
    Posts
    45

    Thumbs up

    Include the link to PDF files in an array, then try a rand... This will load a differente PDF each time page load...

    PHP Code:
    <?php $pdf  = array('link1''link2');
    $numpdf count($pdf);
    $j rand(0$numpdf 1); ?>
    The only thing is that u have to chanche to .php file instead .html
    Then ur full code will be:

    PHP Code:
    <HTML>
    <HEAD>
    <TITLE>Delivery Schedule</TITLE>
    <META HTTP-EQUIV="refresh" CONTENT="600">
    </HEAD>
    <BODY>
    <?php $pdf  = array('link1''link2');
    $numpdf count($pdf);
    $j rand(0$numpdf 1); ?>
    <iframe src="<?php echo $j?>" width="100%" height="100%" FRAMEBORDER="0" MARGINWIDTH="0" MARGINHEIGHT="0" SCROLLING="no"></IFRAME>
    </BODY>
    </HTML>
    Tryit and tell me what sup...

    hope to be helpfull

  4. #4
    Join Date
    Feb 2014
    Posts
    6
    Quote Originally Posted by winthropite View Post
    Why not just put the two reports in two iframes?
    Had thought about that, and could work. At the moment the formatting of the reports wouldn't really fit nicely on the screen we are using. If nothing else works, I will change the report formats to do such, and maybe get the boss to buy a bigger screen!

  5. #5
    Join Date
    Feb 2014
    Posts
    6
    Quote Originally Posted by JCPerez View Post
    Include the link to PDF files in an array, then try a rand... This will load a differente PDF each time page load...

    The only thing is that u have to chanche to .php file instead .html
    Then ur full code will be:

    Tryit and tell me what sup...

    hope to be helpfull
    Great idea, will try it out and let you know!

  6. #6
    Join Date
    Mar 2012
    Posts
    1,651
    It seems to me that, as far as I am aware, the problem is that there is no mechanism to pass a counter with the refresh. But the refresh is, itself, a counter. So why not just set it to an odd number of seconds, e.g. 599, instead of 600? That way, each refresh will occur on an odd or even count of seconds. If the count of seconds is odd, show one web page, if even show the other. E.g.:
    Code:
    <?php
    if(fmod(date('s'),'2')=='1') { $pdf='link1';}
    else {$pdf='link2';}
    ?>
    Last edited by jedaisoul; 02-11-2014 at 05:31 PM.

  7. #7
    Join Date
    Feb 2014
    Posts
    6
    Quote Originally Posted by jedaisoul View Post
    It seems to me that, as far as I am aware, the problem is that there is no mechanism to pass a counter with the refresh. But the refresh is, itself, a counter. So why not just set it to an odd number of seconds, e.g. 599, instead of 600? That way, each refresh will occur on an odd or even count of seconds. If the count of seconds is odd, show one web page, if even show the other. E.g.:
    Code:
    <?php
    if(fmod(date('s'),'2')=='1') { $pdf='link1';}
    else {$pdf='link2';}
    ?>
    Hi Jedaisoul, sounds like a great idea. I just tried it and keep getting a file not found error.
    PHP Code:
    <HTML> 
    <HEAD> 
    <TITLE>Delivery Schedule</TITLE> 
    <META HTTP-EQUIV="refresh" CONTENT="5"> 
    </HEAD> 
    <BODY> 
     
    <?php
    if(fmod(date('s'),'2')=='1') { $pdf='\\SERVER-xxxx\Distribution\LOG\Uncontrolled\Delivery Schedule.pdf';}
    else {
    $pdf='C:\Users\xxxx\Desktop\test.pdf';}
    ?>

    <iframe src="<?php echo $pdf?>" width="100%" height="100%" FRAMEBORDER="0" MARGINWIDTH="0" MARGINHEIGHT="0" SCROLLING="no"></IFRAME>

    </BODY> 
    </HTML>
    Is there something obvious I am doing wrong or leaving out?

  8. #8
    Join Date
    Mar 2012
    Posts
    1,651
    [strike]Firstly, you are using double-quotes instead of single quotes. Single quotes are more appropriate.[/strike] Oops, my tired old eyes!

    Secondly, you have used mixed case, lower case is more reliable.

    Thirdly, there is a space in the file name "Delivery Schedule.pdf". Try renaming it "delivery_schedule.pdf" and amend the code accordingly.

    Fourthly, it is very unlikely that the address "C:\Users\xxxx\Desktop\test.pdf" is accessible to your server!!! Files MUST be located on the server, or within the path of a localhost (if used).

    Fifth, there is a line break between "?" and ">". That may just be an effect of copy/pasting here, but needs to be checked.
    Last edited by jedaisoul; 02-13-2014 at 06:04 PM.

  9. #9
    Join Date
    Feb 2014
    Posts
    6
    Quote Originally Posted by jedaisoul View Post
    [strike]Firstly, ...Fifth,
    Thanks for the response Jedaisoul. I have been through and corrected the code as per your comments and it still gives me the error. At this point I think I will have have x2 iframes on the same page and leave it at that.

    - note for point 4, the "xxx" in the path was just where I removed names to keep things anonymous. In my copy the path files are correct, and work when I don't use php and just use a direct reference in the iframes statement.

    Thanks for all the help.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles