【问题标题】:Meta refresh issue with URL for parent window in firefoxFirefox 中父窗口 URL 的元刷新问题
【发布时间】:2013-01-03 10:59:32
【问题描述】:

在我的网站中,标题包含 twitter 的注销部分。这些注销功能中使用了三个文件。当用户单击注销时,它会打开 twitter 注销 URL,父窗口会刷新并转到 chrome 中的索引页面。

但是在Firefox中父窗口不会刷新。即使在会话销毁后,它也会显示注销,如果我们刷新页面手册,它会显示登录。任何人都可以帮我解决这个问题

Header.php

<li><a href="javascript:;"  onclick="opennewwindow(); clearsession();">Logout</a></li>

function opennewwindow()
{
    var mywin=window.open('twitlogout.php','chindhu','width=550,height=350');
}

function clearsession()
{
var req = GetXmlHttpObject();
req.onreadystatechange = function() {
if(req.readyState == 1) {
document.getElementById('status').innerHTML='<img src="images/ajax-loader.gif"/>';
}   
 if (req.readyState == 4 ) {
     if( req.status == 200) {
document.getElementById('status').innerHTML=req.responseText;
} 
else
{
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
 } 
}  
req.open("GET", "clearsession.php", true);
req.send(null);
}

function GetXmlHttpObject()
{
    if (window.XMLHttpRequest)
      {
      // code for IE7+, Firefox, Chrome, Opera, Safari
      return new XMLHttpRequest();
      }
    if (window.ActiveXObject)
      {
      // code for IE6, IE5
      return new ActiveXObject("Microsoft.XMLHTTP");
      }
    return null;
}

twitlogout.php

<?php
include("header.php");
header("Location:https://twitter.com/#!/logout"); 
?>

clearsession.php

<?php include("config/dbconfig.php");?> 
<meta http-equiv="refresh" content="2;url=<?php echo URLPATH;?>">

<?php
    session_start();
    unset($_SESSION['id']);
    unset($_SESSION['username']);
    unset($_SESSION['oauth_provider']);
    session_destroy();
?>

【问题讨论】:

    标签: php javascript session logout


    【解决方案1】:

    您将clearsession.php 的结果添加到状态元素。元属性刷新需要在标题中,所以这可能是它从未调用过的原因。

    强制 javascript 重新加载页面的最佳方法是使用window.location.reload();。你可以把它放在以下位置:

    if( req.status == 200) {
      document.getElementById('status').innerHTML=req.responseText;
      setTimeout(window.location.reload, 2000); //reload after two seconds
    } 
    

    我在重新加载前使用了两秒的超时时间,但您可以将其设置为您想要的任何值。

    【讨论】:

    • 是的。现在它工作正常。感谢你的回答。 +1 的好答案
    【解决方案2】:

    我们也可以在函数中添加“window.location='our file'”。但缺点是在函数内调用 clearsession.php 时会显示 URL

    function clearsession()
        {
    
                window.location="clearsession.php";
    
        } 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-30
      • 2010-11-21
      • 2011-01-19
      • 1970-01-01
      相关资源
      最近更新 更多