<H3>CIW Web Languages</H3>
<HR>
<FORM NAME="myForm">
<INPUT TYPE="button" VALUE="open new window" onClick="myFunction();">
<!-- Invoke child window function -->
<input type="button" value="Click to open child window" onclick="javascript:myWin.myTest();" />
</FORM>
<P>
JavaScript
function myFunction(){
myWin = open("","","width=200,height=200");
with(myWin.document){
open();
write('<HTML><HEAD><TITLE>Child Window<\/TITLE>');
write('<SCRIPT>function myTest(){');
write('alert("This function is defined in the child window ');
write('and is called from the parent window."); this.focus();}');
write('<\/SCRIPT><\/HEAD><BODY><H3>Child Window<\/H3><HR>');
write('<FORM><INPUT TYPE="button" VALUE="parent window function" ');
// Use opener property
write('onClick="opener.winFunction();">');
write('<P><INPUT TYPE="button" VALUE="close window" ');
write('onClick="window.print();">');
write('<\/FORM><\/BODY><\/HTML>');
close();
}
}
function winFunction(){
alert("This function is defined in the parent window\n" +
"and is called from the child window.");
myWin.focus();
}
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.