当iframe刷新时更改URL



我写了一个页面,里面有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;

详情请参见window.location.href与top.location.href的区别

这是另一种不使用javascript的方法,在count.html

的head标签中放入下面描述的meta标签
<meta http-equiv="Refresh" content="5; url=index.html" />

最新更新