我使用window.open打开了一个窗口 在父窗口保存了这个windwo.open的返回值 也就是子窗口这个对象,但是父页面总要进行一些后台操作 导致页面刷新,然后父窗口保存的这个子窗口的js对象变量就消失了,那么我想在父窗口进行一些对子窗口的操作也无法进行了,请问如何去保存这个变量了。在父页面刷新以后还可以去操作子窗口呢
seesion和cookies的方法基本上已经排除了  session好像是不能保存js的object吧。
cookies不允许使用

解决方案 »

  1.   

    建议父窗口的后台操作建议用AJAX完成就不用刷新了,就能保住那个变量...
      

  2.   

    A页放一个flash,B页也就一个flash,让那二个flash通信就好了
    LocalConnection 和 ExternalInterface ,,代码其实很简单,你分给得多的话,可以帮你写好,  
      

  3.   

    把对象转为字符串保存.用的时候再eval回来
      

  4.   

    没折,JS不能跨页面保存值,一刷新东西就丢了。变通一下的话,可以考虑在子窗口设置timer不断向父窗口写值,传入子窗口的引用,这样父窗口就能重新获得子窗口的引用了。不敢保证肯定可行,试一下吧。
      

  5.   

    用子窗口保存自已.示例: 运行A.htmlA.html<!DOCTYPE html>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <script type="text/javascript">
    var win = null;
    function openWindow(){
    win = window.open("B.html");
    };
    function getSubWindow(){
    win.setSelf(win);

    win.changeParent();
    window.location.href = "C.html";
    }
    </script>
    </head>
    <body>
    源窗口
    <input type="button" value=" Open " onclick="openWindow();" />
    </body>
    </html>
    B.html<!DOCTYPE html>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <script type="text/javascript">
    var thisWin = null;
    var timerID = 0;
    window.onload = function(){
    opener.getSubWindow();
    };
    function setSelf(obj){
    thisWin = obj;
    }
    function callByC(){
    alert("C页面调用!");
    }
    function changeParent(){
    try{
    timerID = setInterval(function(){ opener.setSubWindow(thisWin);}, 100);
    }catch(e){}
    }
    function changeSuccess(){
    clearTimeout(timerID);
    alert("定时器清除!" + timerID);
    }
    </script>
    </head><body>
    window.open 打开的新窗口
    </body>
    </html>C.html<!DOCTYPE html>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <script type="text/javascript">
    var win = null;
    function setSubWindow(obj){
    win = obj;
    win.callByC();
    win.changeSuccess();
    }
    </script>
    </head><body>
    下一个窗口
    </body>
    </html>
      

  6.   

    让子页面帮你把变量缓存下就可以了
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>父页面</title>
    <script type="text/javascript">
    var G_popWin;
    var G_hasLoaded=false;function openPopWin(){
    G_popWin=window.open("sub.html","__popWin");
    }function operateSub(){
    var sHtml;

    if(G_popWin){
    sHtml=G_popWin.document.getElementById("span1").innerHTML;
    alert(sHtml);
    }
    }window.onbeforeunload=function(){
    if(G_popWin){
    G_popWin.cacheVar("G_popWin",G_popWin);
    G_hasLoaded=false;
    G_popWin.injectVar(100);
    }
    }window.onload=function(){
    G_hasLoaded=true;
    };
    </script>
    </head>
    <body>
    <input type="button" value="打开" onclick="openPopWin()"/><br/>
    <input type="button" value="刷新" onclick="location.reload()"/><br/>
    <input type="button" value="获取" onclick="operateSub()"/>
    </body>
    </html>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>子页面</title>
    <script type="text/javascript">
    var G_varMap={};
    var G_scan;function cacheVar(sKey,sVal){
    G_varMap[sKey]=sVal;
    }function injectVar(nInterval){
    var parWin=window.opener;
    G_san=window.setInterval(function(){
    if(parWin.G_hasLoaded){
    for(var key in G_varMap){
    parWin[key]=G_varMap[key];
    }
    window.clearInterval(G_san);
    }
    },nInterval);
    }
    </script>
    </head><body>
    <span id="span1">
    <script type="text/javascript">
    document.write(Math.random(new Date()));
    </script>
    </span>
    </body>
    </html>
      

  7.   

    突然发现一点  用window.open方式打开的子窗口 子窗口的window对象的opener这个属性用永远保持父窗口对象 这个是刷新之类的操作不会去掉的、那么可以设置计时器 不断的通过opener找到父窗口 给父窗口的某个保存子窗口对象的变量不断的刷赋值 这样子也许可以避免这个父窗口的这个变量因为自己页面的刷新而清空  我先继续试试
      

  8.   

    对象转为字符串值为[Object window] ,无法用 eval 获取原来的引用。
      

  9.   

    看一下这个思路行不行
    用框架,父页面index.html是一个框架
    包含两个页面a.html和b.html
    其中a就是 你所说的“父页面”,将a所在的框架设为100%
    b页面所在的框架呢,设置为0。这样就只显示a页面,跟你那父页面效果一样
    然后在b页面里open()出子页面并保存,这样的话,刷新 页面a.html的时候,open的子页面就不会丢失了。
    然后通过index.html 的document.frames进行两个框架间值的传输
      

  10.   

    通讯……把变量先暂存在A页中。或者暂存在cookie中。当操作完成之后,直接提交使用AJAX提交会服务器。