子页面控制父页面跳转

在子页面b用 "opener.location.href="c.html" 控制a页面跳转到c页面

其中a页面为:点击按钮a,打开新窗口b,验证码的存在可在b代码中添加指令,使b点击按钮等后让a页面刷新(暂时没写)。

a.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>
</head>
<script language="javascript" type="text/javascript">
var code ;
function createCode(){ 
code = new Array();
var codeLength = 4;
var checkCode = document.getElementById("checkCode");
checkCode.value = "";
var selectChar = new Array(2,3,4,5,6,7,8,9,'A','B','C','D','E','F','G','H','J','K','L','M','N','P','Q','R','S','T','U','V','W','X','Y','Z');
for(var i=0;i<codeLength;i++) {
var charIndex = Math.floor(Math.random()*32);
code +=selectChar[charIndex];
}
checkCode.value = code;
}
</script>
<script>
function a(){
var openUrl = "b.html";//弹出窗口的url
var iWidth=580; //弹出窗口的宽度;
var iHeight=580; //弹出窗口的高度;
var iTop = (window.screen.availHeight-30-iHeight)/2; //获得窗口的垂直位置;
var iLeft = (window.screen.availWidth-10-iWidth)/2; //获得窗口的水平位置;
window.open(openUrl,"","height="+iHeight+", width="+iWidth+", top="+iTop+", left="+iLeft);
	}
</script>
<script>
function a2(){
window.location.href="c.html"
}
</script>
<body onLoad="createCode();">
<input type="button" id="Button1" onClick="a();" value="a" />
<input type="button" id="checkCode" onClick="createCode()" title="刷新验证码" style="width:50px;color:#F00;border:0;letter-spacing:1px;font-family:Arial;" />
</body>
</html>

b页面有两个按钮,b1的作用,点击后关闭当前窗口,并发送指令使a页面跳转到c页面。b2点击后关闭当前窗口。

<!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>
</head>
<script>
function b1(){
	//window.location.href="c.html"
	opener.location.href="c.html"
	//opener.location.reload();
	window.close();
	}
</script>

<script>
function b2(){
//window.opener=null; 
//window.open('', '_self', ''); 
window.close(); 
//window.location.reload();
	}
</script>

<body>
<input type="button" id="Button1" onClick="b1();" value="b1" />
<input type="button" id="Button2" onClick="b2();" value="b2" />
</body>
</html>

c页面为测试页面,写什么都可以。啦啦啦~


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值