刷新 iframe 时更改 URL
Change URL when iframe refresh
我用iframe写了一个页面,结构如下:
count.html:
/* http://example.com/count.html */
<div class="primary">
<h2>Countdown</h2>
<div class="content">
<iframe src="page2.html" id="iframe"></iframe>
</div>
</div>
index.html:
/* http://example.com/index.html */
<div class="primary">
<h2>Home</h2>
<div class="content">
<iframe src="home.html" id="iframe"></iframe>
</div>
</div>
page2.html:
<head>
<script>
var count = "<!--# echo time -->"; /* C code will control it*/
function display() {
if (wait_seconds == null) {
wait_seconds = (count == "" ? 180 : parseInt(count));
}
document.countdown.b.value = wait_seconds;
if (wait_seconds <= 0) {
if(redirect == null || redirect == "")
redirect = "index.html";
location.href = redirect;
return;
} else {
wait_seconds = wait_seconds-1;
}
window.setTimeout("display()", 1000);
}
</script>
</head>
<body>
<form name='countdown'>
<h2>Countdown Bar</h2>
<input type='text' size='2' name='b' disabled>
</form>
<script>
display();
</script>
</body>
我在iframe中设计了一个倒计时栏(page2.html
)
,时间到了,我想count.html
刷新,改成默认页面index.html
,但是页面刷新时,卡在count.html
,只刷新iframe(page2.html
) ,所以当时间到了,我看到 count.html
有一个 iframe,里面有 index.html
,如何解决?
[window.]location.href
控制当前帧的位置。
使用 [window.]top.location.href
控制最顶层文档的位置。
将location.href = redirectURL;
更改为top.location.href = redirectURL;
有关详细信息,请参阅 Difference between window.location.href and top.location.href。
这是另一种不使用 javascript 的方法,将下面描述的元标记放入 count.html
中的 head 标记中
<meta http-equiv="Refresh" content="5; url=index.html" />
我用iframe写了一个页面,结构如下:
count.html:
/* http://example.com/count.html */
<div class="primary">
<h2>Countdown</h2>
<div class="content">
<iframe src="page2.html" id="iframe"></iframe>
</div>
</div>
index.html:
/* http://example.com/index.html */
<div class="primary">
<h2>Home</h2>
<div class="content">
<iframe src="home.html" id="iframe"></iframe>
</div>
</div>
page2.html:
<head>
<script>
var count = "<!--# echo time -->"; /* C code will control it*/
function display() {
if (wait_seconds == null) {
wait_seconds = (count == "" ? 180 : parseInt(count));
}
document.countdown.b.value = wait_seconds;
if (wait_seconds <= 0) {
if(redirect == null || redirect == "")
redirect = "index.html";
location.href = redirect;
return;
} else {
wait_seconds = wait_seconds-1;
}
window.setTimeout("display()", 1000);
}
</script>
</head>
<body>
<form name='countdown'>
<h2>Countdown Bar</h2>
<input type='text' size='2' name='b' disabled>
</form>
<script>
display();
</script>
</body>
我在iframe中设计了一个倒计时栏(page2.html
)
,时间到了,我想count.html
刷新,改成默认页面index.html
,但是页面刷新时,卡在count.html
,只刷新iframe(page2.html
) ,所以当时间到了,我看到 count.html
有一个 iframe,里面有 index.html
,如何解决?
[window.]location.href
控制当前帧的位置。
使用 [window.]top.location.href
控制最顶层文档的位置。
将location.href = redirectURL;
更改为top.location.href = redirectURL;
有关详细信息,请参阅 Difference between window.location.href and top.location.href。
这是另一种不使用 javascript 的方法,将下面描述的元标记放入 count.html
中的 head 标记中<meta http-equiv="Refresh" content="5; url=index.html" />