S.P.
S.P.

Reputation: 369

Change URL when iframe refresh

I wrote a page with iframe inside, here's the structure:

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>

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?

Upvotes: 1

Views: 920

Answers (2)

U K A
U K A

Reputation: 321

Here's another approach without using javascript, put a meta tag described below into your head tag in count.html

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

Upvotes: 1

arcyqwerty
arcyqwerty

Reputation: 10695

[window.]location.href controls the location of the current frame.

Using [window.]top.location.href controls the location of the topmost document.

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

See Difference between window.location.href and top.location.href for more details.

Upvotes: 2

Related Questions