?
Solved

onbeforeunload in condition

Posted on 2006-07-21
2
Medium Priority
?
405 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 23

Accepted Solution

by:
apresto earned 2000 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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses

777 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