Skip to content Skip to sidebar Skip to footer

How Can I Cycle Through Pages?

Here's a challenge that I was tasked with recently. I still haven't figured out the best way to do it, maybe someone else has an idea. Using PHP and/or HTML, create a page that cy

Solution 1:

<!DOCTYPE htmlPUBLIC"-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd"><htmllang="en"><head><title>Dashboard Example</title><styletype="text/css">body, html { margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden; }
iframe { border: none; }
</style><scripttype="text/javascript">varDash = {
    nextIndex: 0,

    dashboards: [
        {url: "http://www.google.com", time: 5},
        {url: "http://www.yahoo.com", time: 10},
        {url: "http://www.stackoverflow.com", time: 15}
    ],

    display: function()
    {
        var dashboard = Dash.dashboards[Dash.nextIndex];
        frames["displayArea"].location.href = dashboard.url;
        Dash.nextIndex = (Dash.nextIndex + 1) % Dash.dashboards.length;
        setTimeout(Dash.display, dashboard.time * 1000);
    }
};

window.onload = Dash.display;
</script></head><body><iframename="displayArea"width="100%"height="100%"></iframe></body></html>

Solution 2:

Use a separate iframe for the content, then use Javascript to delay() a period of time and set the iframe's location property.

Solution 3:

When you are taken to another site (e.g. Google) control passes to that site, so in order for your script to keep running, you'd need to load the new site in a frame, and keep your script (which I'd imagine could most readily be implemented using Javascript) in another frame (which could be made very small so you can't see it).

Solution 4:

I managed to create this thing. It's not pretty but it does work.

<?php# Path the config file, full or relative.$configfile="config.conf"; 
$tempfile="tmp.html";
# Read the file into an array$farray=file($configfile);  
# Count array elements$count=count($farray);  
if(!isset($_GET['s'])){
    $s=0;
}else{  
    $s=$_GET['s'];
if($s==($count-1)){ # -1 because of the offset in starting our loop at 0 instead of 1$s=0;
}else{
    $s=$_GET['s']+1; # Increment the counter
}
}
# Get the line from the array$entry=$farray[$s];
# Break the line on the comma into 2 entries$arr=explode(",",$entry);       
# Now each line is in 2 pieces - URL and TimeDelay$url=strtolower($arr[0]);
# Check our url to see if it has an HTTP prepended, if it doesn't, give it one.$check=strstr($url,"http://"); 
if($check==FALSE){
    $url="http://".$url;
    }           
# Trim unwanted crap from the time$time=rtrim($arr[1]);               
# Get a handle to the temp file$tmphandle=fopen($tempfile,"w");
# What does our meta refresh look like?$meta="<meta http-equiv=\"refresh\" content=\"".$time.";url=index.php?s=".$s."\">\n";
# The iframe to display$content="<iframe src =\"".$url."\" height=\"100%\" width=\"100%\"></iframe>";
# roll up the meta and content to be written$str=$meta.$content;
# Write it
fwrite($tmphandle,$str);
# Close the handle
fclose($tmphandle);
# Load the pagedie(header("Location:tmp.html"));            
?>

Config files looks like (URL, Time to stay on that page): google.com,5 http://yahoo.com,10

Solution 5:

Depends on your exact requirements. If you allow JavaScript and allow frames then you can stick a hidden frame within a frameset on your page into which you load some JavaScript. This JavaScript will then control the content of the main frame using the window.location object and setTimeout function.

The downside would be that the user's address bar would not update with the new URL. I'm not sure how this would achievable otherwise. If you can clarify the constraints I can provide more help.

Edit - Shad's suggestion is a possibility although unless the user triggers the action the browser may block the popup. Again you'd have to clarify whether a popup is allowable.

Post a Comment for "How Can I Cycle Through Pages?"