Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I cycle through pages?

Tags:

html

php

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 cycles through any number of other pages at a given interval.

For instance, we would load this page and it would take us to google for 20 seconds, then on to yahoo for 10 seconds, then on to stackoverflow for 180 seconds and so on an so forth.

like image 650
GreenO Avatar asked Sep 17 '08 15:09

GreenO


2 Answers

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>Dashboard Example</title>
<style type="text/css">
body, html { margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden; }
iframe { border: none; }
</style>
<script type="text/javascript">
var Dash = {
    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>
<iframe name="displayArea" width="100%" height="100%"></iframe>
</body>
</html>
like image 114
Jonny Buchanan Avatar answered Sep 28 '22 05:09

Jonny Buchanan


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

like image 34
Jason Cohen Avatar answered Sep 28 '22 04:09

Jason Cohen