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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to: !window.focus then window.close 1

Status
Not open for further replies.

toughGirl

MIS
Mar 26, 2001
68
i have this script and it doesn't work. Can someone tell me how to write the code to close the window if it's not in focus?


var newWindow = null
function makeNewWin(){
newWindow = window.open(" "popup", "height=300, width=200")
if (!newWindow.focus){
self.close()
}
}

You can go to and press on the [instructions] link at the bottom.

thanks tG
--{-{@
 
well what your code is saying is this -

open a new window, then if the new window does not have focus, close the parent window

so your logic is wrong and also the line that checks focus is only runs when the function is called, it is not run agian after the first pass...you need to close the window from the popup like this:

first between the <head> tags put

<script language=&quot;javascript&quot;>

function closeWin() {
if(window.blur) {
window.opener.focus();
window.close();
}
}

</script>

then inside the body tag put

onBlur=&quot;closeWin()&quot;

-Greg :-Q

flaga.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top