shane18 Posted February 10, 2010 Share Posted February 10, 2010 How do you check to see if a window exists? Like for example if I pop up a window named SHANE... how do I check to see if window SHANE is still open? Link to comment https://forums.phpfreaks.com/topic/191671-check-if-a-window-exists/ Share on other sites More sharing options...
Psycho Posted February 10, 2010 Share Posted February 10, 2010 You need to create a reference to the window when opening it. You can then use that reference to see if the window was ever opened, is currently open, or has been closed. Here is a quick script that can work with multiple windows (tested in IE and FF) <html> <head> <script type="text/javascript"> var windowObjs = new Array(); function openWindow(windowName) { windowObjs[windowName] = window.open('somepage.htm', windowName); } function windowExist(windowName) { if (!windowObjs[windowName]) { alert('The window "' + windowName + '" has not been opened yet'); } else if(!windowObjs[windowName].closed) { alert('The window "' + windowName + '" is open'); } else { alert('The window "' + windowName + '" has been closed'); } return; } </script> </head> <body> <button onclick="openWindow('test1');">Open Window Test1</button> <button onclick="openWindow('test2');">Open Window Test2</button> <br /><br /><br /> <button onclick="windowExist('test1');">Status of window Test1</button> <button onclick="windowExist('test2');">Status of window Test2</button> </body> </html> Link to comment https://forums.phpfreaks.com/topic/191671-check-if-a-window-exists/#findComment-1010351 Share on other sites More sharing options...
shane18 Posted February 10, 2010 Author Share Posted February 10, 2010 thanks Link to comment https://forums.phpfreaks.com/topic/191671-check-if-a-window-exists/#findComment-1010362 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.