opener.htm:<HTML>
<HEAD>
<TITLE>Master of all Windows</TITLE>
<SCRIPT LANGUAGE="JavaScript1.1">
var myWind
function doNew()
{
if (!myWind || myWind.closed) //attention the condition of "if()"
{
myWind = window.open("opener2.htm","subWindow","HEIGHT=200,WIDTH=350,resizable")
}
else
{
// bring existing subwindow to the front
myWind.focus()
}
}
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME="input">
Select a color for a new window:
<!--<INPUT TYPE="radio" NAME="color" VALUE="red" >Red-->
<INPUT TYPE="radio" NAME="color" VALUE="yellow">Yellow
<INPUT TYPE="radio" NAME="color" VALUE="blue">Blue
<INPUT TYPE="button" NAME="storage" VALUE="Make a Window" onClick="doNew()">
<HR>
This field will be filled from an entry in another window:
<INPUT TYPE="text" NAME="entry" SIZE=25>
</FORM>
</BODY>
</HTML>
opener2.htm:<HTML>
<HEAD>
<TITLE>New Window on the Block</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
function getColor()
{
// shorten the reference
colorButtons = self.opener.document.forms[0].color
// see which radio button is checked
for (var i = 0; i<colorButtons.length; i++)
{
if (colorButtons[i].checked)
{
return colorButtons[i].value
}
}return "white"
}
//-->
</script>
</HEAD>
<!--<SCRIPT LANGUAGE="JavaScript">
document.write("<BODY BGCOLOR='" + getColor() + "'>")
</SCRIPT>-->
<body BGCOLOR="getColor()"> <!--there is the problem-->
<H1>This is a new window.</H1>
<FORM>
<INPUT TYPE="button" VALUE="Who's in the Main window?" onClick="alert(self.opener.document.title)">
Type text here for the main window:
<INPUT TYPE="text" SIZE=25 onChange="self.opener.document.forms[0].entry.value = this.value"><!--attention "this.vlaue"-->
</FORM>
</BODY>
</HTML>
<HEAD>
<TITLE>Master of all Windows</TITLE>
<SCRIPT LANGUAGE="JavaScript1.1">
var myWind
function doNew()
{
if (!myWind || myWind.closed) //attention the condition of "if()"
{
myWind = window.open("opener2.htm","subWindow","HEIGHT=200,WIDTH=350,resizable")
}
else
{
// bring existing subwindow to the front
myWind.focus()
}
}
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME="input">
Select a color for a new window:
<!--<INPUT TYPE="radio" NAME="color" VALUE="red" >Red-->
<INPUT TYPE="radio" NAME="color" VALUE="yellow">Yellow
<INPUT TYPE="radio" NAME="color" VALUE="blue">Blue
<INPUT TYPE="button" NAME="storage" VALUE="Make a Window" onClick="doNew()">
<HR>
This field will be filled from an entry in another window:
<INPUT TYPE="text" NAME="entry" SIZE=25>
</FORM>
</BODY>
</HTML>
opener2.htm:<HTML>
<HEAD>
<TITLE>New Window on the Block</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
function getColor()
{
// shorten the reference
colorButtons = self.opener.document.forms[0].color
// see which radio button is checked
for (var i = 0; i<colorButtons.length; i++)
{
if (colorButtons[i].checked)
{
return colorButtons[i].value
}
}return "white"
}
//-->
</script>
</HEAD>
<!--<SCRIPT LANGUAGE="JavaScript">
document.write("<BODY BGCOLOR='" + getColor() + "'>")
</SCRIPT>-->
<body BGCOLOR="getColor()"> <!--there is the problem-->
<H1>This is a new window.</H1>
<FORM>
<INPUT TYPE="button" VALUE="Who's in the Main window?" onClick="alert(self.opener.document.title)">
Type text here for the main window:
<INPUT TYPE="text" SIZE=25 onChange="self.opener.document.forms[0].entry.value = this.value"><!--attention "this.vlaue"-->
</FORM>
</BODY>
</HTML>
opener.selectElement.click();
opener.select对象名.option[序号].selected=true
opener.select对象名.options[序号].selected=true
===============
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
</HEAD>
<BODY><SELECT id=select1 name=select1 onclick="sel_clk()">
<OPTION>a</OPTION>
<OPTION>b</OPTION>
<OPTION>c</OPTION>
</SELECT><BR>
<INPUT type="button" value="打开新窗口" id=button2 name=button2 onclick="clk_open()">
</BODY>
</HTML>
<script language=javascript>
function sel_clk() {
alert("asd");
}
function clk_open() {
window.open("a.html");
}
</script>
a.html
===============
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
</HEAD>
<BODY><P><INPUT id=button1 type=button value=Button name=button1 onclick="clk()"></P></BODY>
</HTML>
<script language=javascript>
function clk() {
window.opener.select1.click();
}</script>
opener.select对象名.options[序号].selected=true
这样作:父窗口中select的一个option项确实被选中了,但不会触发select的onClick事件。我自己这样解决了:原来可以直接用opener对象调用父窗口中的自定义函数,
在弹出窗口中:window.opener.selectItem()
而父窗口中的select控件对应的onClick()事件也是调用selectItem()事件,这样就可以了。
也谢谢 slumcherry的代码(太多了没看明白....)
但是出现的效果有点怪:select列表如果滚动,会先滚动到最上面的options项显示,然后再滚动到选中项。