user4fun Posted July 19, 2007 Share Posted July 19, 2007 I got this code form the site, <script type="text/javascript">function open_win() {window.open("http://www.microsoft.com/")window.open("http://www.w3schools.com/")}</script></head><body><form><input type=button value="Open Windows" onclick="open_win()"></form> What would i need to put in there to have a ntoher button that would close all the windows that were just opened.?Thank you Link to comment Share on other sites More sharing options...
jesh Posted July 19, 2007 Share Posted July 19, 2007 Two things would need to happen. The first is that you would need to record a reference to those windows so that you could close them at some other time. The second would be to write the function.So, change the open_win function to something like this: // first, we need a global reference to the windowsvar win1, win2;function open_win(){ // rather than just opening the windows, open the windows // and save a reference to the windows in our variables win1 = window.open("http://www.microsoft.com/"); win2 = window.open("http://www.w3schools.com/");} Then, write a close_win function: function close_win(){ // first, check to see that the win1 variable // is defined and then check to see if it is open if(win1 && win1.closed == false) { // everything's good, close the window win1.close(); } // repeat the steps above for win2. if(win2 && win2.closed == false) { win2.close(); }} You could then call the function with a new button: <input type="button" value="Close Windows" onclick="close_win();" /> Link to comment Share on other sites More sharing options...
aspnetguy Posted July 19, 2007 Share Posted July 19, 2007 or for each individual window you could place a button like this to close the window fromt he popup itself <input type="button" value="Close Window" onclick="window.close()" Link to comment Share on other sites More sharing options...
user4fun Posted July 20, 2007 Author Share Posted July 20, 2007 Thankx for the reply folks, i think i am gong ot use the first code, then there will about 10 windows to open up.Thank you Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.