PDA

View Full Version : detect if window exists



tylerjca
Jun 7th, 2006, 08:58 PM
I'm having a problem detecting if a window exists. The popup works, but when it checks for the window, it says it doesn't exist.
maybe i'm not calling the window correctly...

here's my code:


function makePopup(){
if(window.open('http://yahoo.com/','new_page')){
alert('Successfully opened window!');
}
else{
alert('Please disable any popup blockers you may have!');
}
}

function checkPopup(){
if(!window.new_page){
alert('Window does NOT exist');
}
else{
alert('Window Exists');
}
}

Mr J
Jun 7th, 2006, 09:43 PM
Give this a try


<script type="text/javascript">

newWin=null

function makePopup(){
newWin=window.open('http://yahoo.com/','new_page')
}

function checkPopup(){
if(newWin&&!newWin.closed){
alert('Window Exists');
}
else{
alert('Window does NOT exist');
}
}

</script>

<a href="#null" onclick="makePopup()">Make Popup</a>

<a href="#null" onclick="checkPopup()">Check Popup</a>

tylerjca
Jun 7th, 2006, 10:44 PM
excellent! thanks that works great! :) :thumbsup: