0

I have a web page. On this page I have a DIV that is getting a feed from another PHP page. This feed also have a countdown. I want when the count reaches 0 only the page in the DIV to redirect to my destination of choice. Here is what I am using below:

function CountDown(t){
var s,c,countdown;
s= 6;
c=$('#count');

countdown = setInterval(function(){
c.html("Redirecting in " + s);
if (s == 0) {

  window.location.href="Forums";
  return false;
}
s--;
}, 1000);
}

Now Here is what the HTMl looks like;

<html>
//header stuff
<body>
//html stuff
<div id="Mypage"></div>
//some more html stuff
</body>
</html>

The Page in question is in the DIV with id = Mypage. What I would like is for when the countdown reaches zero the page redirects but in this case it is redirecting the entire main page. Is it possible for it to only redirect the page in the DIV to a new location? I am sure that my code window.location.href is the reason this is happening but I am not sure how to make only the page in the DIV redirect.

Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724
Bryan
  • 258
  • 2
  • 12

2 Answers2

3

You can use jQuery.load() to load content into a particular div like so:

$('#result').load('ajax/test.html', function() {
  alert('Load was performed.');
});

To replace just the body of the inner page, try this from the script within the inner page:

$('body').replaceWith(data);

or

$('body').html(data);
RHarrington
  • 999
  • 1
  • 8
  • 12
  • I deleted my post as I completely forgot about this. I found [this post](http://stackoverflow.com/q/9963799/1506793) which should provide you with some more details. – Zachary Kniebel Apr 12 '13 at 18:49
  • This I tried before but the javascript count down is on the page in the div not the main page so this did not work. – Bryan Apr 12 '13 at 18:49
  • @Bryan - if that is the case then what you are trying to do is not possible without more code - update your OP with this new information and I will add a new answer – Zachary Kniebel Apr 12 '13 at 18:51
  • Yeah, I was going to update, as well, but you gave the best and simplest possible answer and you deserve the credit. :) – Zachary Kniebel Apr 12 '13 at 18:52
  • @Bryan - are you trying to replace the div with the countdown with the content of a new page? – RHarrington Apr 12 '13 at 18:54
0

Load new contents in Mypage Div like this.

$("#Mypage").load(urlToLoad);
Adil Shaikh
  • 44,509
  • 17
  • 89
  • 111