我使用window.open打开了一个窗口 在父窗口保存了这个windwo.open的返回值 也就是子窗口这个对象,但是父页面总要进行一些后台操作 导致页面刷新,然后父窗口保存的这个子窗口的js对象变量就消失了,那么我想在父窗口进行一些对子窗口的操作也无法进行了,请问如何去保存这个变量了。在父页面刷新以后还可以去操作子窗口呢
seesion和cookies的方法基本上已经排除了 session好像是不能保存js的object吧。
cookies不允许使用
seesion和cookies的方法基本上已经排除了 session好像是不能保存js的object吧。
cookies不允许使用
LocalConnection 和 ExternalInterface ,,代码其实很简单,你分给得多的话,可以帮你写好,
<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>
<!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>
用框架,父页面index.html是一个框架
包含两个页面a.html和b.html
其中a就是 你所说的“父页面”,将a所在的框架设为100%
b页面所在的框架呢,设置为0。这样就只显示a页面,跟你那父页面效果一样
然后在b页面里open()出子页面并保存,这样的话,刷新 页面a.html的时候,open的子页面就不会丢失了。
然后通过index.html 的document.frames进行两个框架间值的传输