今天遇到一个问题,在193页面上
<iframe frameborder="0" width="100%" scrolling="auto"
style="margin-top: -4px;" οnlοad="this.style.height=document.body.clientHeight"
height="100%" src="http://advs.VVV.org/190.jsp"></iframe>
在190页面上
<script type="text/javascript">
window.open("http://www.csdn.net/","_self");
</script>
访问193.jsp跳转到http://www.csdn.net/这个页面,但是url上还是193.jsp
上网查询发现一篇不错的文章就转过来了,
将190.jsp上
<script type="text/javascript">
window.parent.open("http://www.csdn.net/","_self");
</script>
问题解决啦,访问193.jsp的时候会正常跳转到http://www.csdn.net/上,并且url网址也改变了
打开新窗口一般有几种方法,window.open(...),window.showModalDialog(...),以及iframe中嵌套页面这里也一起研究吧,另外还有window.navigate(...)、window.location.href="..."、window.history.back(-1);都是实现同意页面内容跳转的,这里不讨论。
1、open子窗口:用window.opener代表父窗口的window对象
2、模态子窗口:间接通过传window对象到子窗口,然后子窗口可获得父窗口的window对象
3、iframe中子页面:用window.parent代表父窗口的window对象
父页面:1.htm 代码:
<html>
<head>
<title>打开父子窗口传值研究-父窗口</title>
<script >
var parValue="现在显示了父窗口中的变量值";
function test(){
alert("现在显示了父窗口中的方法正常执行");
}
</script>
</head>
<body >
<input type="button" id="mybutton1" value="打开open新窗口" οnclick="window.open('2.htm');">
<input type="button" id="mybutton2" value="打开modal窗口" οnclick="window.showModalDialog('3.htm',window);" >
<br>
<iframe id="subiframe" name="subiframe" src="4.htm" scrolling="auto" frameborder="1" ></iframe>
</body>
</html>
2.htm 代码:
<html>
<head>
<title>打开父子窗口传值研究-open打开子窗口</title>
<script>
var buttonValue=window.opener.document.getElementById("mybutton2").value //获取父窗口中的对象
var parentValue=window.opener.parValue; //获取父窗口中的变量
function doParTest(){
window.opener.test(); //调用父窗口中的方法
}
</script>
</head>
<body>
<input type="button" value="open打开子窗口按钮" οnclick="alert('buttonValue:'+buttonValue);alert('parentValue:'+parentValue);doParTest()">
</body>
</html>
3.htm 代码:
<html>
<head>
<title>打开父子窗口传值研究-打开modal子窗口</title>
<script>
var parentWin=window.dialogArguments;
var buttonValue=parentWin.document.getElementById("mybutton2").value //获取父窗口中的对象
var parentValue=parentWin.parValue; //获取父窗口中的变量
function doParTest(){
parentWin.test(); //调用父窗口中的方法
}
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<input type="button" value="modal子窗口按钮" οnclick="alert('buttonValue:'+buttonValue);alert
('parentValue:'+parentValue);parentWin.test();">
</body>
</html>
4.htm 代码:
<html>
<head>
<title>打开父子窗口传值研究-iframe中子窗口</title>
<script>
var buttonValue=window.parent.document.getElementById("mybutton2").value //获取父窗口中的对象
var parentValue=window.parent.parValue; //获取父窗口中的变量
function doParTest(){
window.parent.test(); //调用父窗口中的方法
}
</script>
</head>
<body>
<input type="button" value="iframe中子窗口按钮" οnclick="alert('buttonValue:'+buttonValue);alert('parentValue:'+parentValue);doParTest()">
</body>
</html>
转自:http://ningzhengping.blog.sohu.com/82006712.html