Solved

Are you sure you want to leave this page warning

Posted on 2014-03-18
3
1,716 Views
Last Modified: 2014-03-22
I noticed on few sites, if the process is not finished and in between user wants to leave the page then the browser shows this warning.

Are you sure you want to leave this page?

Have you saved your files?

[Leave this page] [Stay on this page]


I saw this in the IE but crome also does the same job.


I have asp.net page which has log form which user needs to fill.
I also need to stop user by showing this same message when he tries leave the page without saving the changes first.

how can I do this?
0
Comment
Question by:yadavdep
  • 2
3 Comments
 
LVL 29

Expert Comment

by:Olaf Doschke
ID: 39938936
That's about Javascript events.

http://www.technicaladvices.com/2012/03/26/detecting-the-page-leave-event-in-javascript/

I don't know how you best make use of this in ASP.NET, but since it's a client side event it has to be done in Javascript anyway. Do you use jQuery? ASP.NET MVC?

Bye, Olaf.
0
 

Author Comment

by:yadavdep
ID: 39938973
Hi Olaf,

 I am using Asp.net and yes I do use Jquery in it
0
 
LVL 29

Accepted Solution

by:
Olaf Doschke earned 175 total points
ID: 39939635
Then you can make use of the more specific jQuery event handling.

$(window).bind('beforeunload', function(){
		return 'Are you sure you want to leave without saving changes?';
	});

Open in new window


And like in the other example given, you can decide whether to show such a warning message by checking, if the user entered something into a form element, which should not get lost.

Return null, if you want to let the user leave without further notice.

Bye, Olaf.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

930 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now