简体   繁体   English

iframe刷新时更改URL

[英]Change URL when iframe refresh

I wrote a page with iframe inside, here's the structure: 我在里面用iframe写了一个页面,这里是结构:

count.html: 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: 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: 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>

I designed a countdown bar in the iframe( page2.html ) , when time's up, I want count.html refresh and change to the default page index.html , but when page refresh, it stucked in count.html and only refresh the iframe( page2.html ), so when time's up, I saw count.html has a iframe with index.html inside, how to fix it? 我在iframe( page2.html )设计了一个倒计时栏,当时间到了,我想要count.html刷新并更改为默认页面index.html ,但是当页面刷新时,它停留在count.html并且只刷新iframe ( page2.html ),所以当时间到了,我看到count.html有一个带有index.html的iframe,如何解决?

[window.]location.href controls the location of the current frame. [window.]location.href控制当前帧的位置。

Using [window.]top.location.href controls the location of the topmost document. 使用[window.]top.location.href控制最顶层文档的位置。

Change location.href = redirectURL; 更改location.href = redirectURL; to top.location.href = redirectURL; to top.location.href = redirectURL;

See Difference between window.location.href and top.location.href for more details. 有关更多详细信息,请参阅window.location.href和top.location.href之间的区别

这是另一种不使用javascript的方法,将下面描述的元标记放入count.html的head标记中

<meta http-equiv="Refresh" content="5; url=index.html" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM