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

Detect Answer to window.close prompt 1

Status
Not open for further replies.

techie99

Programmer
Joined
Apr 24, 2003
Messages
60
Location
US
How do I detect the selection the user made to the prompt "The web page you are viewing is trying to close the window". How can I detect whether they chose 'yes' or 'no'. I need an event to happen if they choose 'no'.
 
if (prompt("The web page you are viewing is trying to close the window")){
....

}else{
....

}
 

IIRC, you can't close the window without the user's say-so unless you opened it in the first place.

This is just as well cause it would be a real pain if any site could just kill your browser when you didn't want them to.

You can maybe get around it by changing the settings, or setting yourself as a trusted site.

 
wow - i actually read the whole post.

theboyhope is right - about this and your other post, I think you need to rethink your solution, it seems to me you a getting too clever and aren't too sure of the limitations of the browser.
 
He wasn't asking how to close the browser without prompting the user, he was asking how to detect if they chose "No" from the prompt. Here's the solution:

<script>
function closeWindow(){
window.close()
setTimeout(&quot;stillOpen()&quot;,50)
}
function stillOpen(){
alert('This get executed if they choose No');
}
</script>

Adam
while(ignorance==true){perpetuate(violence,fear,hatred);life--};
 

Hey, that's a good point, mate. Well done.
 

Just checked this in Mozilla, and it seems that Mozilla makes the &quot;No&quot; choice for you. &quot;Scripts may not close windows that were not opened by script&quot; is the error given.

Just FYI.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top