javascript cancel close window

Posted on 2009-05-27
Medium Priority
Last Modified: 2012-05-07
hi to all,
(For Internet explorer 7.0)
1-i want to show a message to user when close explorer window. i've done it but when i explore in same domain  the message appear always. I just want to show message when user try to close window. not as surf same domain. if user go another domain so show message too..
2-Is there any way to cancel window close?

window.onbeforeunload = closeWindow;

Open in new window

Question by:erenpasa

Accepted Solution

random_ru earned 2000 total points
ID: 24485150
window.onbeforeunload = function () {
   return "You have not saved your document yet.  If you continue, your work will not be saved."

http://www.hunlock.com/blogs/Mastering_The_Back_Button_With_Javascript     for more info
LVL 14

Expert Comment

ID: 27332121
1- it is impossible to capture the destination url of the next page for security reasons, so you can't do that.

2- you can cancel window close by returning false with
window.onbeforeunload = function() { return false; }
BUT you also can't leave the current page to another, which means it also can't be done.

Featured Post

Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…

607 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