Use HTML to open a new window and write to it
There are times when you want to create a window with spacific information. The
previous demos opened a new window with an html document. Now create a new window and
fill it with HTML. Think of the HTML document that opens the new window as the parent
and the window that is being created as the child. To do this define a variable
that will be used to open the window and
format the html. Then not only can you send information to the child window, you can also
send information back to the parent window that opened it.
First create an html document that will create the child window and write html to it.
The demo is an html document that creates a child with three links on it. One link will close
the parent window and one link will close the child window and the third will change the satus bar
on the parent window to "parent".
- Notice the first two links have been given names "parentclose" and "childclose"
- Javascript can be used on the parent to access the child, change the status bar on the parent to "parent"
- Javascript can be used on the child to access the parent, change the status bar on the child to "stuff"
JavaScript on the parent window:
- get the name of the first link on the child window
popupWindow.document.links[0].name;
- Get the name of the child window
alert(popupWindow.name);
- to change the status on the child
popupWindow.defaultStatus='stuff';
JavaScript on the child window:
-
close the parent - notice when the child tries to close the parent, a prompt comes up to make sure you
want to close the parent window.
<a name="parentclose" href="#" onclick="parent.opener.close();return false;">
- close the child
<a name="childclose" href="#" onclick="self.close();">
- change the name of the parent status bar to "parent"
<a href="#" onclick="javascript:parent.opener.status=\'parent\';return false;">
click here to see the demo.