dongyi1996 2019-06-20 15:06
浏览 75

从框架中的脚本重定向页面

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?

  • 写回答

2条回答 默认 最新

  • dswqz24846 2019-06-20 15:13
    关注

    Assuming your pages, both the parent and the one in the iframe, are on the same domain, you can easily call window.parent from the frame and redirect that way.

    window.parent.location.href = '/whatever-page';
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?