[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Detecting Browser Close Event and calling a function before browser closes

Posted on 2006-05-16
1
Medium Priority
?
474 Views
Last Modified: 2008-02-07
Hello,

I have a JavaScript question.

I need to determine if the user clicked on a [X] button. I then need to display a dialog with either Yes|No or Yes|Cancel buttons. Based on the response of the user, I need to be able to call a function BEFORE the browser closes. The platform is always WINDOWS and browser is always IE.

I have looked into the onBeforeUnload event and I can even determine if the user clicked [X] as opposed to refresh and such by using event.clientY property. I can display a message before the browser closes. What I need is to be able to display the alert and based on either user pressed Yes or Cancel - I need to be able to call a function that will do something BEFORE the browser is closed. If the user pressed cancel - I need for the browser to remain open.

I know this is a complicated one and I would give it more that 500 points - but 500 is MAX :)

Any thoughts or ideas would be appreciated.
0
Comment
Question by:mactep13
1 Comment
 
LVL 5

Accepted Solution

by:
arunrs earned 1500 total points
ID: 16691901
Try this
Inside your onBeforeUnload function add this content.

if(confirm ("Your Message here"))
{
    CallFunction();
    return true;
}
else
{
    return false;
}


Also, for the onBeforeUnload event add "return onbeforeunloadFunction();"

Hope this is useful.

arunrs
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question