Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How stop event onBeforeUnload in Javascript.

Posted on 2005-04-01
4
Medium Priority
?
1,783 Views
Last Modified: 2008-02-07
In my application, i need to stop the event onBeforeUnload  when tu user press 'X' to close.
I want use my own "CloseWindow()" method.
I don't want to see the Window Dialog when the "return" is set.
I want to stop the event before to see this dialog.

For exemple:

function window_onunload()
{
   // DO SOMETHING TO STOP THIS EVENT
   myCloseWindow();
}

Any solutions are welcomes
Please, help!

Thanks
Sebastien



0
Comment
Question by:scarri
2 Comments
 
LVL 25

Accepted Solution

by:
James Rodgers earned 252 total points
ID: 13683953
i'm pretty sure onBeforeUnload is IE only, but you could try this


document.onbeforeunload=function myFunc(){return false}
0
 
LVL 29

Assisted Solution

by:rdivilbiss
rdivilbiss earned 248 total points
ID: 13684720
The cross browser comand you are looking for is (traditional)

window.onunload = myCloseWindow();

In the more advance W3C Dom model (not widely supported) this would be,

window.addEventListener ('unload',myCloseWindow(),false);

http://www.quirksmode.org/js/events_compinfo.html

It is not possible to cancel the unloading of the page.  You can only specify the event handler to be used.

And of course, none of this works if the browser has JavaScript disabled.

Good Luck with your project.
Rod

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
Why WooCommerce is one of the majorly favored choices when it comes to having an eCommerce store. This article will acquaint you with some reasons that I believe make it one of the best eCommerce platforms available.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses
Course of the Month10 days, 12 hours left to enroll

572 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