如何在页面中循环?

时间:2022-09-26 11:01:03

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.

使用PHP和/或HTML,创建一个以给定间隔循环任意数量的其他页面的页面。

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 * for 180 seconds and so on an so forth.

例如,我们将加载此页面,它将需要我们谷歌20秒,然后到雅虎10秒,然后到堆栈溢出180秒等等。

12 个解决方案

#1


18  

<!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.*.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>

#2


1  

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

对内容使用单独的iframe,然后使用Javascript延迟()一段时间并设置iframe的location属性。

#3


1  

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).

当你被带到另一个网站(例如谷歌)时,控制传递到该网站,所以为了让你的脚本继续运行,你需要在一个框架中加载新网站,并保留你的脚本(我想象的)最容易使用Javascript)在另一个框架中实现(可能会非常小,所以你看不到它)。

#4


1  

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 page
die(header("Location:tmp.html"));            
?>

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

配置文件看起来像(URL,停留在该页面上的时间):google.com,5 http://yahoo.com,10

#5


0  

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.

取决于您的确切要求。如果您允许使用JavaScript并允许框架,那么您可以在页面上的框架集中粘贴一个隐藏框架,您可以在其中加载一些JavaScript。然后,此JavaScript将使用window.location对象和setTimeout函数控制主框架的内容。

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.

缺点是用户的地址栏不会使用新URL更新。我不确定这会如何实现。如果您能澄清限制,我可以提供更多帮助。

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.

编辑 - Shad的建议是可能的,但除非用户触发操作,浏览器可能会阻止弹出窗口。再次,您必须澄清是否允许弹出窗口。

#6


0  

Create a wrapper HTML page with an IFrame in it, sized at 100% x 100%. Then add in some javascript that changes the src of the IFrame between set intervals.

创建一个包含IFrame的包装器HTML页面,大小为100%x 100%。然后添加一些javascript,在设置的时间间隔之间更改IFrame的src。

#7


0  

I think it would have to work like gabbly.com, which sucks in other websites and displays them with its own content over it.

我认为它必须像gabbly.com一样工作,它会吸引其他网站,并通过它自己显示内容。

Once you read the other site in and were ready to display it, you couldn't really do it "in PHP"; you would have to send an HTML redirect meta-tag:

一旦你阅读了其他网站并准备好显示它,你就无法“在PHP中”真正做到这一点;您必须发送HTML重定向元标记:

<meta HTTP-EQUIV="REFRESH" content="15; url=http://www.thepagecycler.com/nextpage.html">

Or you could use Javascript instead of the meta-tag.

或者您可以使用Javascript而不是元标记。

#8


0  

This is not doable in a PHP script, unless you want to edit the redirect.... PHP is a back end technology; you're going to need to do this in Javascript or the like.

这在PHP脚本中是不可行的,除非你想编辑重定向.... PHP是一种后端技术;你需要在Javascript等中做这件事。

The best you're going to do, as far as I know, is to create a text file on your web server and load a different HTTP address based on time out of that text file, then redirect the browser to the site found in that text file.

据我所知,您要做的最好的事情是在Web服务器上创建一个文本文件,并根据该文本文件的超时时间加载不同的HTTP地址,然后将浏览器重定向到该文本中找到的站点。文本文件。

#9


0  

The first solution that jumps to mind is to do this in a frameset. Hide one of the frames, and the other display the pages in question. Drive the page transitions with Javascript from the hidden frame.

跳到脑海的第一个解决方案是在框架集中执行此操作。隐藏其中一个框架,另一个框架显示相关页面。使用隐藏框架中的Javascript驱动页面过渡。

function RefreshFrame()
{
    parent.VisibleFrame.location.href = urlArray[i];
    i++;

    if(i < urlArray.length) SetTimeout("RefreshFrame()", 20000);
}

var i = 0;
var urlArray = ['http://google.com','http://yahoo.com', 'http://www.search.com'];
RefreshFrame();

In this example the Javascript would be in the hiddend frame, and you would name your visible frame "VisibleFrame".

在此示例中,Javascript将位于hiddend框架中,您可以将可见框命名为“VisibleFrame”。

Disclaimer: I just wrote this code in the comment window and have not tested it

免责声明:我刚刚在评论窗口中编写了此代码,并且尚未对其进行测试

#10


0  

You could do this with JavaScript quite easily. It would help to know the deployment environment. Is it a kiosk or something?

你可以很容易地用JavaScript完成这个。了解部署环境将有所帮助。它是亭子还是什么?

For the JavaScript solution, serve up a page that contains a JavaScript that will pop open a new browser window. The controller page will then cause the new browser window to cycle through a series of pages. That's about the simplest way to do this that I can think of.

对于JavaScript解决方案,请提供包含将弹出新浏览器窗口的JavaScript的页面。然后,控制器页面将使新浏览器窗口循环显示一系列页面。这是我能想到的最简单的方法。

Edit: Agree with Simon's comment. This solution would work best in a kiosk or large, public display environment where the pages are just being shown without any user interaction.

编辑:同意Simon的评论。此解决方案在自助服务终端或大型公共显示环境中效果最佳,其中页面仅在没有任何用户交互的情况下显示。

#11


0  

The theory behind the request is basically the ability to cycle through web page dashboards for various systems from a "kiosk" PC. I oversee a data center and we have several monitor systems that allow me view dashboards for temps, system up time, etc etc. The idea is load a page that would cycle from dashboard to dashboard remaining on each for an amount of time specified by me, 1 minute on this board, 30 seconds on the next board, 2 minutes on the next and so on.. Javascript is absolutely allowable (though I have little experience with it). My mediums of choice are PHP/HTML and I'm not seeing a way to make this happen cleanly with just them..

请求背后的理论基本上是从“自助服务终端”PC循环浏览各种系统的网页仪表板的能力。我监督一个数据中心,我们有几个监控系统,允许我查看仪表板的温度,系统运行时间等。这个想法是加载一个页面,从仪表板循环到仪表板,每个页面保留一段我指定的时间,在这个板上1分钟,在下一个板上30秒,在下一个板上2分钟等等... Javascript是绝对允许的(虽然我对它有一点经验)。我选择的媒介是PHP / HTML,我没有看到一种方法可以让它干净利落地发生。

#12


-1  

There's a bunch of ways you can do this, iv written several scripts and tools with everything from JS to Ruby

有很多方法可以做到这一点,iv编写了几个脚本和工具,包括从JS到Ruby的所有内容

In the end It was much easier to use http://dashboardrotator.com . It handled browser restarts, memory allocation and accidental window closure for me with a nice simple GUI.

最后使用http://dashboardrotator.com要容易得多。它通过简单的GUI处理浏览器重启,内存分配和意外窗口关闭。

#1


18  

<!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.*.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>

#2


1  

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

对内容使用单独的iframe,然后使用Javascript延迟()一段时间并设置iframe的location属性。

#3


1  

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).

当你被带到另一个网站(例如谷歌)时,控制传递到该网站,所以为了让你的脚本继续运行,你需要在一个框架中加载新网站,并保留你的脚本(我想象的)最容易使用Javascript)在另一个框架中实现(可能会非常小,所以你看不到它)。

#4


1  

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 page
die(header("Location:tmp.html"));            
?>

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

配置文件看起来像(URL,停留在该页面上的时间):google.com,5 http://yahoo.com,10

#5


0  

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.

取决于您的确切要求。如果您允许使用JavaScript并允许框架,那么您可以在页面上的框架集中粘贴一个隐藏框架,您可以在其中加载一些JavaScript。然后,此JavaScript将使用window.location对象和setTimeout函数控制主框架的内容。

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.

缺点是用户的地址栏不会使用新URL更新。我不确定这会如何实现。如果您能澄清限制,我可以提供更多帮助。

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.

编辑 - Shad的建议是可能的,但除非用户触发操作,浏览器可能会阻止弹出窗口。再次,您必须澄清是否允许弹出窗口。

#6


0  

Create a wrapper HTML page with an IFrame in it, sized at 100% x 100%. Then add in some javascript that changes the src of the IFrame between set intervals.

创建一个包含IFrame的包装器HTML页面,大小为100%x 100%。然后添加一些javascript,在设置的时间间隔之间更改IFrame的src。

#7


0  

I think it would have to work like gabbly.com, which sucks in other websites and displays them with its own content over it.

我认为它必须像gabbly.com一样工作,它会吸引其他网站,并通过它自己显示内容。

Once you read the other site in and were ready to display it, you couldn't really do it "in PHP"; you would have to send an HTML redirect meta-tag:

一旦你阅读了其他网站并准备好显示它,你就无法“在PHP中”真正做到这一点;您必须发送HTML重定向元标记:

<meta HTTP-EQUIV="REFRESH" content="15; url=http://www.thepagecycler.com/nextpage.html">

Or you could use Javascript instead of the meta-tag.

或者您可以使用Javascript而不是元标记。

#8


0  

This is not doable in a PHP script, unless you want to edit the redirect.... PHP is a back end technology; you're going to need to do this in Javascript or the like.

这在PHP脚本中是不可行的,除非你想编辑重定向.... PHP是一种后端技术;你需要在Javascript等中做这件事。

The best you're going to do, as far as I know, is to create a text file on your web server and load a different HTTP address based on time out of that text file, then redirect the browser to the site found in that text file.

据我所知,您要做的最好的事情是在Web服务器上创建一个文本文件,并根据该文本文件的超时时间加载不同的HTTP地址,然后将浏览器重定向到该文本中找到的站点。文本文件。

#9


0  

The first solution that jumps to mind is to do this in a frameset. Hide one of the frames, and the other display the pages in question. Drive the page transitions with Javascript from the hidden frame.

跳到脑海的第一个解决方案是在框架集中执行此操作。隐藏其中一个框架,另一个框架显示相关页面。使用隐藏框架中的Javascript驱动页面过渡。

function RefreshFrame()
{
    parent.VisibleFrame.location.href = urlArray[i];
    i++;

    if(i < urlArray.length) SetTimeout("RefreshFrame()", 20000);
}

var i = 0;
var urlArray = ['http://google.com','http://yahoo.com', 'http://www.search.com'];
RefreshFrame();

In this example the Javascript would be in the hiddend frame, and you would name your visible frame "VisibleFrame".

在此示例中,Javascript将位于hiddend框架中,您可以将可见框命名为“VisibleFrame”。

Disclaimer: I just wrote this code in the comment window and have not tested it

免责声明:我刚刚在评论窗口中编写了此代码,并且尚未对其进行测试

#10


0  

You could do this with JavaScript quite easily. It would help to know the deployment environment. Is it a kiosk or something?

你可以很容易地用JavaScript完成这个。了解部署环境将有所帮助。它是亭子还是什么?

For the JavaScript solution, serve up a page that contains a JavaScript that will pop open a new browser window. The controller page will then cause the new browser window to cycle through a series of pages. That's about the simplest way to do this that I can think of.

对于JavaScript解决方案,请提供包含将弹出新浏览器窗口的JavaScript的页面。然后,控制器页面将使新浏览器窗口循环显示一系列页面。这是我能想到的最简单的方法。

Edit: Agree with Simon's comment. This solution would work best in a kiosk or large, public display environment where the pages are just being shown without any user interaction.

编辑:同意Simon的评论。此解决方案在自助服务终端或大型公共显示环境中效果最佳,其中页面仅在没有任何用户交互的情况下显示。

#11


0  

The theory behind the request is basically the ability to cycle through web page dashboards for various systems from a "kiosk" PC. I oversee a data center and we have several monitor systems that allow me view dashboards for temps, system up time, etc etc. The idea is load a page that would cycle from dashboard to dashboard remaining on each for an amount of time specified by me, 1 minute on this board, 30 seconds on the next board, 2 minutes on the next and so on.. Javascript is absolutely allowable (though I have little experience with it). My mediums of choice are PHP/HTML and I'm not seeing a way to make this happen cleanly with just them..

请求背后的理论基本上是从“自助服务终端”PC循环浏览各种系统的网页仪表板的能力。我监督一个数据中心,我们有几个监控系统,允许我查看仪表板的温度,系统运行时间等。这个想法是加载一个页面,从仪表板循环到仪表板,每个页面保留一段我指定的时间,在这个板上1分钟,在下一个板上30秒,在下一个板上2分钟等等... Javascript是绝对允许的(虽然我对它有一点经验)。我选择的媒介是PHP / HTML,我没有看到一种方法可以让它干净利落地发生。

#12


-1  

There's a bunch of ways you can do this, iv written several scripts and tools with everything from JS to Ruby

有很多方法可以做到这一点,iv编写了几个脚本和工具,包括从JS到Ruby的所有内容

In the end It was much easier to use http://dashboardrotator.com . It handled browser restarts, memory allocation and accidental window closure for me with a nice simple GUI.

最后使用http://dashboardrotator.com要容易得多。它通过简单的GUI处理浏览器重启,内存分配和意外窗口关闭。