JS 父窗口向子窗口传值问题(window.open())

方法一~~~~~~~~~~~~~~~~~~~~~~
主窗口:
<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>

你可能感兴趣的:(JS 父窗口向子窗口传值问题(window.open()))