javascript cancel close window

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

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

window.onbeforeunload = function () {
   return "You have not saved your document yet.  If you continue, your work will not be saved."

or     for more info

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Samuel LiewCommented:
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.