Current location: Hot Scripts Forums » General Web Coding » JavaScript » Confirm on close?


Confirm on close?

Reply
  #1 (permalink)  
Old 01-09-04, 08:46 AM
Icarus Icarus is offline
New Member
 
Join Date: Jan 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Confirm on close?

Hi!

I've read one earlier question about 'confirming on exit' and I have pretty much the same question since the examples did not really work for me. I would like a javascript that when the user close the window (and ONLY close NOT when he/she clicks the backbutton) an alert message displays. This popupmessage should have both an "ok"-button and a "cancel"-button so the user can choose to go back to the page and close the message if he/she wants to OR close the window completely.

Is there anyone out there who has any idea? I guess this must be a pretty easy script for those who knows who to do it..

Thanx in advance!

/Icarus
Reply With Quote
  #2 (permalink)  
Old 01-09-04, 10:52 AM
spikemeister spikemeister is offline
Newbie Coder
 
Join Date: Jan 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Reply With Quote
  #3 (permalink)  
Old 01-09-04, 10:47 PM
gwx gwx is offline
Newbie Coder
 
Join Date: Dec 2003
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Netscape automatically displays a message.
Reply With Quote
  #4 (permalink)  
Old 01-12-04, 03:45 AM
Icarus Icarus is offline
New Member
 
Join Date: Jan 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Thanx...

Hi again!

Thanx for the answer, I really appreciate it! It is almost the script I am looking for although I don't want a close-button IN the page. I only want the popupmessage to appear when I try to close the window. I mean when I press the x-button (for instance in Explorer) in the list of the window I have open.

Is this possible?

Thanx so much in advance.

/Icarus
Reply With Quote
  #5 (permalink)  
Old 01-17-04, 02:02 PM
delerium's Avatar
delerium delerium is offline
Newbie Coder
 
Join Date: Jan 2004
Location: pittsburgh
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
its not to hard

its a pretty easy script:
function closeMe()
{
result=window.confirm("do you really want to close me?");
{
if (result==true){window.alert(result);}
else{window.alert(result);}
}
}
the above goes in the head.

your body tag would look like this:
<body onUnload="closeMe();">
now, all you have to do is change what happens when the variable, result, is made either true or false. right now all its doing is printing out the variable. hope this helps

--delerium--
Reply With Quote
  #6 (permalink)  
Old 01-17-04, 02:05 PM
MadDog MadDog is offline
Code Master
 
Join Date: Aug 2003
Posts: 935
Thanks: 0
Thanked 0 Times in 0 Posts
The window will still close even if you press the X button.
__________________
Drew Gauderman
ASP - MSSQL Coder / Buisness Owner / Coder for Hire!
MSN-ICQ-AIM-YIM in Profile

http://www.iportalx.net an easy ASP portal system.
Reply With Quote
  #7 (permalink)  
Old 01-31-04, 05:59 PM
rugantino rugantino is offline
New Member
 
Join Date: Jan 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Hi to everyone, I've found this thread by looking for the same thing... on Google . Right now I found this, that works on IE only but at least it's better than nothing (put anywhere in your page):

Code:
<script>
window.onbeforeunload = unloadMess;
function unloadMess(){
mess = "Going away... so bad..."
return mess;
}
</script>
It's what I was looking for, but it works for IE only and it's quite verbose lol... Anything better? Let me know...

Last edited by rugantino; 01-31-04 at 06:10 PM.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Close CD door CrackerBox JavaScript 0 11-07-03 02:11 PM
close form sasi ASP 4 08-26-03 03:51 AM


All times are GMT -5. The time now is 11:44 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.