1

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?

asked Sep 15, 2015 at 3:42
2
  • I don't see countdown.html anywhere Commented Sep 15, 2015 at 3:50
  • @TomSarduy fixed it, thank you Commented Sep 15, 2015 at 3:54

2 Answers 2

2

[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.

answered Sep 15, 2015 at 4:05
Sign up to request clarification or add additional context in comments.

Comments

1

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" />
answered Sep 15, 2015 at 4:56

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.