Solved

Are you sure you want to leave this page warning

Posted on 2014-03-18
3
1,738 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Device Location 4 29
jquery progress bar 3 40
https://github.com/willowsystems/jSignature 11 46
Get distinct values from excel or comm seperated file 4 23
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

776 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