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.

2 Answers 2

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);
5
  • I deleted my post as I completely forgot about this. I found this post which should provide you with some more details. Apr 12, 2013 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, 2013 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 Apr 12, 2013 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. :) Apr 12, 2013 at 18:52
  • @Bryan - are you trying to replace the div with the countdown with the content of a new page? Apr 12, 2013 at 18:54
0

Load new contents in Mypage Div like this.

$("#Mypage").load(urlToLoad);

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.