Solved

onbeforeunload in condition

Posted on 2006-07-21
2
398 Views
Last Modified: 2008-03-06
I have the following command that ask the user if he is sure he wants to exit the page:
<body onbeforeunload="return ' '">
I want to have this only in case I have changes in the page that the user did not save.
How can I check it and how do I give a condition in this place in the < BODY>
Thankyou
Anat
0
Comment
Question by:ANAT2403
2 Comments
 
LVL 23

Accepted Solution

by:
apresto earned 500 total points
ID: 17158017
when you say Save what do you mean?

If you mean a form then you could create a function to store the value of form fields when thje page was first loaded, then have them compare when they leave the page, if they are different you could show the error:  i.e

(paste this into a blank document and name it with a .html extension and run it)_

<html>

<head>
<script>
var oldVal = "";

function saveValues()
{
   oldVal = document.myForm.tester.value;
}

function checkChanges()
{
  if ( oldVal != document.myForm.tester.value )
   { return 'Are you sure you wish to exit dude?';}
}

</script>
</head>
<BODY onload="saveValues();" onbeforeunload="return checkChanges();">
<form name="myForm">
<input type="text" name="tester">
</form>

</body>

</html>
0
 

Author Comment

by:ANAT2403
ID: 17160422
That's very nice.
What is left is the problem of the refresh. I wrote you in the .NET forum. Can you help?
Thankyou
Anat
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

744 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

12 Experts available now in Live!

Get 1:1 Help Now