Solved

onbeforeunload in condition

Posted on 2006-07-21
2
404 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 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When you work with shopping cart / ecommerce relates web sites, you need to pass the certain form post details to the payment gateway process page with required details for the products items you give to order. Also you may need to track the ordered…
Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

687 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