回答你的問題之前取消它,我不得不說這是一個非常糟糕的做法,你可以使用jQuery和jQuery Slider Plugin,它會更有效。
做你想做的事就是更加複雜的iframe,但你可以做到。你應該用iframe onload事件改變當前頁面的索引(i),
這裏是你如何能做到,
<script type="text/javascript">
var pages=new Array();
pages[0]="/budget.html";
pages[1]="/voluntary.html";
pages[2]="/robust.html";
var i=0;
var time=4000; // this is set in milliseconds
var timer = false;
var timerSetter;
function pageChange() {
document.getElementById("agencyframe").src=pages[i];
i++;
if(i==pages.length) {
i=0;
}
timerSetter = setTimeout("pageChange()",time);
}
function contentChanged(e) {
if (!timer) { pageChange(); timer=true;}
if (timerSetter) {
clearTimeout(timerSetter);
timerSetter = setTimeout("pageChange()",time);
}
var newSrc = e.contentWindow.location.href;
for (var j=0; j < pages.length; j++) {
if (newSrc.match(pages[j])) {
i = j+1;
if(i==pages.length) {
i=0;
}
}
}
}
</script>
而且不要忘記設置了iframe的onload屬性,
<iframe id="agencyframe" onload="contentChanged(this)" src="/budget.html">
</iframe>
UPDATE:
據我瞭解,你想改變的iframe頁面時用戶點擊(零頁頁單頁二)on this page.
你可以改變這樣的iframe的位置,
document.getElementById("agencyframe").src = "/budget.html";
因此改變你的功能就是這樣,
function pageZero() {
document.getElementById("prin_div1").setAttribute("class", "prin_on");
document.getElementById("prin_div2").setAttribute("class", "prin_off");
document.getElementById("prin_div3").setAttribute("class", "prin_off");
document.getElementById("agencyframe").src = pages[0];
}
function pageOne() {
document.getElementById("prin_div1").setAttribute("class", "prin_off");
document.getElementById("prin_div2").setAttribute("class", "prin_on");
document.getElementById("prin_div3").setAttribute("class", "prin_off");
document.getElementById("agencyframe").src = pages[1];
}
function pageTwo() {
document.getElementById("prin_div1").setAttribute("class", "prin_off");
document.getElementById("prin_div2").setAttribute("class", "prin_off");
document.getElementById("prin_div3").setAttribute("class", "prin_on");
document.getElementById("agencyframe").src = pages[2];
}
UPDATE -2:
變化contentChanged
之類的函數這個,
function contentChanged(e) {
if (!timer) { pageChange(); timer=true;}
if (timerSetter) {
clearTimeout(timerSetter);
timerSetter = setTimeout("pageChange()",time);
}
var newSrc = e.contentWindow.location.href;
for (var j=0; j < pages.length; j++) {
if (newSrc.match(pages[j])) {
i = j+1;
document.getElementById("prin_div"+i).setAttribute("class", "prin_on");
if(i==pages.length) {
i=0;
}
} else {
document.getElementById("prin_div"+(j+1)).setAttribute("class", "prin_off");
}
}
}
感謝您的建議。我確實想到了這一點,但問題是他們變成了如何動態地改變控制器來打開/關閉,因爲頁面要麼直接從控制器中按順序動態加載。目前,我有三種控制器版本,對應於他們在 – 2012-04-24 16:31:31
上顯示的頁面。它肯定不會是一個大問題 - 點擊控制器會將點擊的控制器翻轉到開啓狀態(通過CSS輕鬆實現附加一個類時);否則setTimeout調用的函數將通過三個控制器的數組進行旋轉,加載相應的頁面並將控制器設置爲'on'。定位導航系統時,這是一個常見問題,您可以在線找到大量資源。 – Armatus 2012-04-24 16:37:40