Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

close window 1

Status
Not open for further replies.

ascikey

Programmer
Feb 18, 2004
127
GB
Hi all, I am doing a tutorial that creates a window but how do I make a link to go in the new window so that it can be closed by clicking Close.
Code:
<html>
<head>
<script language="JavaScript">
<!-- hide script from browser
function openWin3()
 {
  myWin=open("", "displayWindow", "width=500,hight=400,status=yes,toolbar=no,menubar=no");
  
  //open document for further output
  myWin.document.open();

  //create document
  myWin.document.write("<html><head><title>on-the-fly");
  myWin.document.write("</title></head><body>");
  myWin.document.write("<center><font size=3>");
  myWin.document.write("Document has been created on the fly");
  myWin.document.write("</font></center>");
  myWin.document.write("</font></center>");
  myWin.document.write("</body></html>");

  //Close the document (not the window!)
  //myWin.document.close();
 }
 //-->
</script>
  
</head>
<body>

<form>
<input type=button value="On-the-fly" onClick="openWin3()">
</form>
</body>
</html>

I would also like to know what the line “myWin.document.close();” actually does.
thx
 
window.close()

There's always a better way. The fun is trying to find it!
 
hi thx for your reply.
i had tried to use window.close() but not sure where to put it or how to link it to the <a href tag ie
Code:
function openWin3()
 {
  myWin=open("", "displayWindow", "width=250,hight=100,status=yes,toolbar=no,menubar=no");
  
  //open document for further output
  myWin.document.open();

  //create document
  myWin.document.write("<html><head><title>on-the-fly");
  myWin.document.write("</title></head><body>");
  myWin.document.write("<center><font size=3>");
  myWin.document.write("Document has been created on the fly");
  myWin.document.write("</font></center>");
  myWin.document.write("</font></center>");
  myWin.document.write("<a href='window.close()'> Close</a>");
  myWin.document.write("</body></html>");

  //Close the document (not the window!)
  myWin.document.close();
 }

But as suspected this just gives the page not found
 
Okay, this is what you need:
Code:
function openWin3()
 {
  myWin=window.open("", "displayWindow", "width=250,hight=100,status=yes,toolbar=no,menubar=no");
  xwin="<head><title>on-the-fly</title></head><body><center><font size=3>" +
	"Document has been created on the fly</font></center>" +
	"<a href='javascript:self.close()'>Close</a></body>";
 
  //create document
  myWin.document.write(xwin);
  myWin.document.close();
}

Study this little - I've changed your version significantly.

There's always a better way. The fun is trying to find it!
 
thx for ur reply & changes i will have a study of them
thx again
 
Thanks that works great and obviously has a much better use of the document .write
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top