Bryan
Bryan

Reputation: 358

How to redirect a page in javascript or jquery

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.

Upvotes: 0

Views: 160

Answers (2)

RHarrington
RHarrington

Reputation: 1049

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);

Upvotes: 3

Adil Shaikh
Adil Shaikh

Reputation: 44740

Load new contents in Mypage Div like this.

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

Upvotes: 0

Related Questions