我正在尝试开发一个程序,该程序将每10秒钟在URL位置之间切换一次,然后在转到最后一个URL后循环。描述下面:
- 显示10秒的url1
- 显示10秒的URL2
- 显示10秒的URL3
- 循环回到URL(连续循环)
我相信这可以使用Settimeout和循环完成。我对Settimeout和Java没有完全的了解,因此这就是我目前所困扰的地方。我在下面放置了一个代码,但是由于我不知道如何使用settimeout认为这是我的第一个错误。
如果有更好的方法来做到这一点,我全都是耳朵。我一直在尝试使用Java 3天,因为它需要在工作中进行一个项目,所以我对此非常崭新,可能是我的头部。
<!DOCTYPE>
<html>
<body>
"urls"
<script>
var myurl;
function urls()
{
myurl=setTimeout(url1,0);
myurl=setTimeout(url2,10000);
myurl=setTimeout(url3,20000);
}
function url1()
{
<embed width="100%" height="100%" name=plugin src="http://files.asme.org/ICOMES/News/15876.pdf#pagemode=none&scrollbar=0&page=2" type="application/pdf".;
}
function url2()
{
<embed width="100%" height="100%" name=plugin src="http://www.tbp.org/pubs/Features/Su04McMasters.pdf#pagemode=none&scrollbar=0&page=2" type="application/pdf".;
}
function url3()
{
<embed width="100%" height="100%" name=plugin src="http://milproj.dc.umich.edu/publications/EngFlex_report/download/EngFlex%20Report.pdf#pagemode=none&scrollbar=0&page=2" type="application/pdf".;
}
</script>
</body>
</html>
编辑:
<!DOCTYPE>
<html>
<body>
<script>
var urlList = ['http://www.google.com', 'http://www.msn.com', 'http://www.yahoo.com'];
var wnd;
var curIndex = 0; // a var to hold the current index of the current url
function openWindow(){
wnd = window.open(urlList[curIndex], '', '');
setTimeout(function () {
wnd.close(); //close current window
curIndex++; //increment the index
if(curIndex < urlList.length) openWindow(); //open the next window if the array isn't at the end
}, 2000);
}
openWindow();
</script>
</body>
</html>
不是java。是JavaScript;)您可以在HTML中进行一个iFrame,并使用JavaScript每10秒更改其源。
例如:
<html>
<body>
<iframe id="theIframe" src="">
</iframe>
</body>
<script>
function timeout() {
setTimeout(function () {
document.getElementById("theIframe").src= 'http://www.google.com';
timeout();
}, 10000);
}
timeout();
</script>
<html>
我不确定这个确切的代码是否有效,因为我只是在没有测试的情况下编写了它。但是您可以得到一个总体想法。这样每10秒就可以重新加载Google。您可以对其进行修改,以便从数组或其他内容中获取网站。
并非所有浏览器都会支持直接在浏览器中打开PDF。有些人可能想下载它 - 取决于插件。如果要渲染PDF,则可能需要外部库。