Link to home
Start Free TrialLog in
Avatar of creditpointe
creditpointe

asked on

How do I suppress " Are you sure you want to navigate away from this page" message through code

I am closing the browser through Java Script. When I do so I am getting a message from the IE asking me "Are you sure you want to navigate away from this page?" . I want to suppress this message either through HTML/Java Script/jquery. Please help.
Avatar of creditpointe
creditpointe

ASKER

Ref ths image for above question.
InternetExplorer-Image.JPG
Avatar of Gurvinder Pal Singh
do
window.onbeforeunload = null;
window.onunload = null;

have you checked this link
http://userscripts.org/topics/35250
It can't be done any more. Javascript will not return that message only when the window was opened by using a window.open. Javascript cannot close a window it didn't open without prompting for confirmation. You used to be able to fool i by setting the windows current opener to something other than null but that is no longer the case with IE 8.

Cheers,

Lee
And we are clapping our hands that web site creators no longer can mess with our main browser window.
A solution wasn't provided as there isn't one.  The question was correctly answered it just wasn't the answer that was wanted so I object to the question being deleted.
lsavidge,
The team here is still exploring a few things. Let's keep this open for a while then.


ModEErf:,
Thank you.
I've requested that this question be closed as follows:

Accepted answer: 500 points for lsavidge's comment #a26152719

for the following reason:

This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
Actually. The horrible hack still worked in IE8
ASKER CERTIFIED SOLUTION
Avatar of dimmergeek
dimmergeek
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I think the original question was asking about closing a window that wasn't opened via a script. You can close any window you open with a script without a confirmation, but you cannot close a browser window that wasn't opened via a script without you being prompted. The loophole in IE was considered a hack and a security risk which is why it no longeer works.
I've had another look at the proposed solution in #a39503932 from dimmergeek. Now I've had time to sleep on it I see it now.

So, this opens a new page which is designed to close itself but it opens it in the _parent frame, which if the page is the top frame will act as if it is _self but then it immediately closes itself. As the page was opened via a script, the page will close without warning.

Indeed, to confirm it to myself, I tested it and it does exactly that. Ingenious!

I stand firmly corrected. Points should be awarded to dimmergeek and not me as that solution does work.

It feels dirty, but I like it!
Thanks lsavidge.
I've been using this dirty liittle trick for a long time.
I have several web pages that are automatically called to perform database updates and I needed a way to ensure that they closed and didn't leave open sessions.
I'll be adding this baby to my knowledge base on here.
Thank you.