hello. I'm a new javascript programmer and I need you help! I wrote the following code:
<HTML>
<HEAD>
<TITLE> A2P3 </TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
var w=null;
function openWindow(){
var options="resizable=1,toolbar=1,scrollbars=1,menubar=0,status=0,location=0,directories=0, width=300,height=300";
w=window.open("","NewWindow",options);
makepage="<HTML><title> New Window </title>";
makepage +="<BODY><form><center><h1> New Window </h1>";
makepage +="<hr size = '2' width = '100%' color = 'gray' /><br/>";
makepage +="<input type='button' value='Green Color to the parent window' onClick='opener.document.bgcolor='green';' /><br/><br/>";
makepage +="<hr size = '2' width = '100%' color = 'gray' /><br/>";
makepage +="<input type='button' value='Close' onClick='window.close();' /><br/>";
makepage +="</form></center></body></html>";
w.document.write(makepage);
}
function changeColor(){
if(w==null){
window.alert("child window is not opened! Do you want to open it?");
openWindow();
}
w.document.bgColor="red";
}
function writeText(){
text=window.document.form1.NewText.value;
w.document.writeln(text);
}
function changeParent() {
opener.document.bgcolor = "green";
window.focus();
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<form name="form1">
<input type="button" value="Open new window" onClick="openWindow();" /><br/><br/>
<input type="button" value="Red background color to the new window" onClick="changeColor();" /><br/><br/>
<input type="button" value="Text to the new window" onClick="writeText();" />
<input type="text" name = "NewText" size = "30" />
</form>
</BODY>
</HTML>
I use two windows. The child one is called w. The problem is that the first button of the child window, which must change the background color of the parent one is not working at all! Can you help me find what's wrong?
Thanks a lot
<HTML>
<HEAD>
<TITLE> A2P3 </TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
var w=null;
function openWindow(){
var options="resizable=1,toolbar=1,scrollbars=1,menubar=0,status=0,location=0,directories=0, width=300,height=300";
w=window.open("","NewWindow",options);
makepage="<HTML><title> New Window </title>";
makepage +="<BODY><form><center><h1> New Window </h1>";
makepage +="<hr size = '2' width = '100%' color = 'gray' /><br/>";
makepage +="<input type='button' value='Green Color to the parent window' onClick='opener.document.bgcolor='green';' /><br/><br/>";
makepage +="<hr size = '2' width = '100%' color = 'gray' /><br/>";
makepage +="<input type='button' value='Close' onClick='window.close();' /><br/>";
makepage +="</form></center></body></html>";
w.document.write(makepage);
}
function changeColor(){
if(w==null){
window.alert("child window is not opened! Do you want to open it?");
openWindow();
}
w.document.bgColor="red";
}
function writeText(){
text=window.document.form1.NewText.value;
w.document.writeln(text);
}
function changeParent() {
opener.document.bgcolor = "green";
window.focus();
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<form name="form1">
<input type="button" value="Open new window" onClick="openWindow();" /><br/><br/>
<input type="button" value="Red background color to the new window" onClick="changeColor();" /><br/><br/>
<input type="button" value="Text to the new window" onClick="writeText();" />
<input type="text" name = "NewText" size = "30" />
</form>
</BODY>
</HTML>
I use two windows. The child one is called w. The problem is that the first button of the child window, which must change the background color of the parent one is not working at all! Can you help me find what's wrong?
Thanks a lot