dongping4901 2015-06-28 09:51
浏览 40
已采纳

从iframe中的页面打开链接作为普通页面

Good morning,

Recently I was playing around trying to build a simple chat room for educational reasons. On my login/register/welcome screen I have a button that opens a login.php file on an iframe so that you can login. If you put the correct username and password stored in a database it redirects you to the ./chat/index.php page (the main chat room page). The problem is that this page opens inside the iframe. Is there a way to make it open on the same window as a normal page like how a simple button link would do.

This is my code on the main page:

<div id="login" class="menu">
<h4>I have an account :)</h4>
<form method="get" action="./login" target="loginFrame">
    <button type="submit" onclick="showLoginFrame">Please let me in so I can talk with my friends!</button>
</form>
<iframe id="loginIframe" name="loginFrame" frameborder="0" scrolling="no"></iframe>
<script type="text/javascript">  
  function showLoginFrame() {  
    var iframe1 = document.getElementById("loginIframe");  
    iframe1.style.visibility="visible";
  }
</script>

And this is the part of the code on the login php page (the one that does all the work with the db) that redirects to the chat page:

if($user == $dbusername && $pass == $dbpassword)
   {
    session_start();
     $_SESSION['sess_user']=$user;
/* Redirect browser */
    header("Location: ../chat/");
   }
} else {
    echo "Invalid username or password!<br><br>";
}
  • 写回答

1条回答 默认 最新

  • douyi1341 2015-06-28 10:29
    关注

    While I agree with @Ofir Baruch you should consider a dialog instead, placing the below javascript on your ./chat/index.php should bust it out of the frame.

    if (top.location!= self.location) {
       top.location = self.location.href;
    }
    

    In the event this does not work for you there are two other solutions here:

    https://css-tricks.com/snippets/javascript/break-out-of-iframe/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了