User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 402,911 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,082 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 2617 | Replies: 2
Reply
Join Date: Aug 2007
Posts: 1
Reputation: newbeein is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
newbeein newbeein is offline Offline
Newbie Poster

Question Delay Window Close

  #1  
Sep 3rd, 2007
Hi Experts,

I am using mozilla firefox 1.5. I want to delay the page close when the user clicks on the close (X) button of the browser. I want to display something like "Closing Please wait......" for 5 seconds (run a code in the background) and then close the window after 5 seconds.

Till the time the "Closing Please wait......" is displayed, the window should not close. after 5 seconds, it will as it is close because the user has clicked the browser's close button.

Is there a way I can do this ?

Regards

/nbi
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2006
Location: Deptford, London
Posts: 943
Reputation: MattEvans has a spectacular aura about MattEvans has a spectacular aura about 
Rep Power: 5
Solved Threads: 47
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is offline Offline
Posting Shark

Re: Delay Window Close

  #2  
Sep 3rd, 2007
Why on earth would you want to do something so outright annoying? If I click close, I want closed.

No, there isn't an easy away to do this. You can catch the body "onunload" javascript event, and run code there; but it doesn't mean the same thing in different browsers. Regardless, you cannot 'cancel' or 'delay' the closing of the page or browser.*

Imagine the user accessing a page as them opening and closing their browser simultaneuously; that's effectively how HTTP works. You can't make any assumptions about what the user ( or browser ) does once they have downloaded your page, and certainly don't view them as being 'on' your page; they're just looking at a copy of it.


EDIT: * just to add, it's not possible in most ( all modern ? ) browsers, for reasonable security reasons, not because it would be technically difficult.
Last edited by MattEvans : Sep 3rd, 2007 at 8:43 am.
If it only works in Internet Explorer; it doesn't work.
Reply With Quote  
Join Date: Jul 2006
Location: Deptford, London
Posts: 943
Reputation: MattEvans has a spectacular aura about MattEvans has a spectacular aura about 
Rep Power: 5
Solved Threads: 47
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is offline Offline
Posting Shark

Re: Delay Window Close

  #3  
Sep 3rd, 2007
Well. it seems firefox truely sucks, it allows this:
  1. <html>
  2. <head></head>
  3. <body onunload="while( true ){ alert( 'hi' ); }">
  4. </body>
  5. </html>
which executes when the user closes the browser, or navigates away from the page. Opera doesn't, because Opera's a good browser, and even if it did, one could break out of it quickly.

That only works to 'delay' the browser closing because alert is a blocking function; it doesn't return until the user clicks ok. if you could find another blocking function that isn't so insidious, you could run that.. or even 'while' loop repeatadly. It'll only work for firefox ( and likely IE to be honest ), and it'll likely annoy your users... but hey.. also, the browser window closes fully in FF2, and an alert just pops up until the program's terminated manually... so, you can't 'see' the page behind atall, but you can execute any code you desire to.
Last edited by MattEvans : Sep 3rd, 2007 at 8:58 am.
If it only works in Internet Explorer; it doesn't work.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JavaScript / DHTML / AJAX Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 3:45 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC