I am loading a page every 4th second (lobby_box.php) using javascript. This page is being loaded in a div on my (index.php) page. The problem is that (lobby_box.php) contains a code that should redirect the client from index.php > anotherpage.php. But it redirects the client to (anotherpage.php) inside the div that loads the (lobby_box.php) every 4th second.
So basically, it doesn't redirect the whole page, just the inside the div.
I have tried using everything I can get my hands on. I've been trying to redirect using javascript, jquery, php codes but it still only redirects inside the div.
function getLobbyBox() {
var http;
if (window.XMLHttpRequest) {
http = new XMLHttpRequest();
} else if (window.ActiveXObject) {
http = new ActiveXObject("Microsoft.XMLHTTP");
}
http.onreadystatechange=function()
{
if (http.readyState==4 && http.status==200)
{
document.getElementById("lobby_new_content").innerHTML= http.responseText;
}
}
http.open("GET", "includes/lobby_box.php?noCache=" + Math.random(), true);
http.send();
}
This is the function that loads (lobby_box.php) every 4th second.
This is the code that should redirect to anotherpage.php but only redirects to it inside the div.
if(mysqli_num_rows($game) > 0) {
echo '<script>window.location.href = "/anotherpage.php";</script>';
exit();
}
I've also tried
if(mysqli_num_rows($game) > 0) {
header('location: anotherpage.php');
exit();
}
Is it even possible to solve it like that? Or do I need to find another way?