主窗口:
<input name="" type="button" onclick="newpage()"/>
<script>
var a = "12345"
function newpage(){
window.open("子窗口.html" + "?" + a)
}
</script>
子窗口.html
<script>
var addstr= document.URL
var num=addstr.indexOf("?")
addstr=addstr.substr(num+1)
alert(addstr)
</script>
方法二:~~~~~~~~~~~~~~~~~~~~~~~
主窗口:
<input id="hid" type="hidden" value="" />
<input name="" type="button" onclick="newpage()"/>
<script>
var a = "12345"
function newpage(){
document.getElementById("hid").value = a
window.open("2.html")
}
</script>
子窗口:
<script>
var prtW = window.opener
var prtA
if(prtW!=null){
prtA = prtW.document.getElementById("hid").value
alert(prtA)
}
</script>
我在IE7下运行页面,可以把子窗口中的值传到父窗口中也可以这样改
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>New Document </TITLE>
<script type="text/javascript">
function openWindow() {
window.open("childen.html")
}
</script>
</HEAD>
<BODY>
<input type="button" value="打开新窗口" onclick="openWindow()">
<hr>
这是父窗口<br>
<input id="content" type="text" name="content" >
</BODY>
</HTML>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>New Document </TITLE>
<script type="text/javascript">
function execute() {
var value = document.getElementsByName("content")[0].value
window.opener.document.getElementById("content").value=value
window.close()
}
</script>
</HEAD>
<BODY>
<input type="text" name="content" value="这是子窗口">
<input type="button" value="确定" onclick="execute()">
</BODY>
</HTML>
父窗口添加<input type="hidden" id="s"/>
子窗口
window.parent.docuent.getElementById("s").value=s
父窗口获得传的值
var str = document.getElementById("s").value
alert(str)