douying8666 2013-01-03 10:59
浏览 62
已采纳

在Firefox中父窗口的URL的元刷新问题

In my site, header contains logout section for twitter. Three files are used in these logout functionality. When the user click logout, it opens the twitter logout URL and the parent window refreshe and goes to index page in chrome.

But the parent window does not refresh in firefox. Even after the session destroy, it shows logout and if we refresh the page manual it shows sign in. Anybody can help me to solve this problem

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:
" + 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();
?>
  • 写回答

2条回答 默认 最新

  • dongnuoyi8833 2013-01-03 11:24
    关注

    You are adding the result of the clearsession.php to the status element. The meta property refresh needs to be in the header, so that might be why its never called.

    The best way to force javascript to reload the page is to use window.location.reload();. You can put that at the following location:

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

    I am using a timeout of two seconds before the reload, but you can set it to whatever you want.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染