473,513 Members | 2,270 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Warn to Save before leaving a page...

I've got a form that's nested in a larger application. I need to
program it so that the user is warned to save upon clicking on any
exit point in the application.

So, if they click on any of the nav buttons in the header/nav bar,
they need to get an alert:

"Would you like to continue without saving your changes?"
_Yes_ _No_

It would be a big pain to retrofit the application's nav
buttons/framework for just these forms, so I'm looking for a solution
that doesn't require editing the source code of the application's
existing navigation.

What are my options?

BTW, this application is for IE 5+ only, FWIW.

Thanks,
Jamie
Jul 20 '05 #1
5 18870
Jamie Jackson wrote:
So, if they click on any of the nav buttons in the header/nav bar,
they need to get an alert:

"Would you like to continue without saving your changes?"
_Yes_ _No_


<body onunload="if (confirm('Save changes?')) { doSomethingHere(); }">

Jul 20 '05 #2
On Fri, 10 Oct 2003 00:31:24 +0100, bengee
<po********@localhost.localdomain> wrote:
Jamie Jackson wrote:
So, if they click on any of the nav buttons in the header/nav bar,
they need to get an alert:

"Would you like to continue without saving your changes?"
_Yes_ _No_


<body onunload="if (confirm('Save changes?')) { doSomethingHere(); }">


Great! It still requires me to modify the application framework, but
at least it's only in one place (good news). :)

Thanks very much,
Jamie

Jul 20 '05 #3
On Fri, 10 Oct 2003 09:53:11 -0400, Jamie Jackson
<wa***************@bigfoot.com> wrote:
On Fri, 10 Oct 2003 00:31:24 +0100, bengee
<po********@localhost.localdomain> wrote:
Jamie Jackson wrote:
So, if they click on any of the nav buttons in the header/nav bar,
they need to get an alert:

"Would you like to continue without saving your changes?"
_Yes_ _No_


<body onunload="if (confirm('Save changes?')) { doSomethingHere(); }">


Great! It still requires me to modify the application framework, but
at least it's only in one place (good news). :)


I think this isn't going to work. AFAIK, by the time you get the
confirmation, you've already unloaded the page, and are halfway to the
next. Is there a way to prevent the unLoad from continuing, when the
user confirms in the negative?

I'm racking my brain trying to figure out how to do this without
retrofitting all of the nav links.

I think I may be on to something with the following, would someone
please let me know if I'm going in the right direction, or if there's
an easier way, or if there's a solution to the onUnload issue above?

function changeLinks(d) {
// this picks up all the links but those in my popup nav :-( ...it's
a start, though
for (var i=0; i < d.links.length; i++) {
// maybe save each link's old location into an array here, for
later use

// now, rewrite each link to a confirm. later, code the following
to load a new window with the old url?
d.links[i].href = "javascript: confirm('Exit before saving?')";
}
}
changeLinks(document);

Thanks,
Jamie
Jul 20 '05 #4
Jamie Jackson wrote:
I think this isn't going to work. AFAIK, by the time you get the
confirmation, you've already unloaded the page, and are halfway to the
next. Is there a way to prevent the unLoad from continuing, when the
user confirms in the negative?
I think you're right there... the page is already on it's way to
"unloading" and i don't think that can be stopped.
I'm racking my brain trying to figure out how to do this without
retrofitting all of the nav links.

I think I may be on to something with the following, would someone
please let me know if I'm going in the right direction, or if there's
an easier way, or if there's a solution to the onUnload issue above?

function changeLinks(d) {
// this picks up all the links but those in my popup nav :-( ...it's
a start, though
for (var i=0; i < d.links.length; i++) {
// maybe save each link's old location into an array here, for
later use

// now, rewrite each link to a confirm. later, code the following
to load a new window with the old url?
d.links[i].href = "javascript: confirm('Exit before saving?')";
}
}
changeLinks(document);


This looks like a good way of doing it. Change the href's to something
like :-

d.links[i].href = "javascript: if (confirm('Exit?')) {
document.location.href = 'somefile.htm'; } else { void(0); }";

Hope this works!!

Ben

Jul 20 '05 #5
Thanks again Ben,

Here's what I came up with:

<script language="JavaScript1.2">
function promptBeforeExiting (oldLink) {
if (confirm("Exit without saving?")) {
window.location = oldLink;
}
}

function switchLinks(d) {
var oldLink="";
for (var i=0; i < d.links.length; i++) {
oldLink = d.links[i].href;
d.links[i].href = "javascript: promptBeforeExiting('"+ oldLink + "')";
}
}
switchLinks(document);
</script>

It's working very well for <a href>s, and now I've got to figure out
how to disable my popup links as well...

Thanks,
Jamie
Jul 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
8397
by: Marco Alting | last post by:
Hi, I have an HTML form which enters data in an Access database using ASP. But now my client asked me if it is possible to alert users, when they click a link other then submit on the page, that...
1
421
by: Ryan Moore | last post by:
I'm trying to make a page that, when opened, displays a file save dialog, then closes itself (essentially just leaving the file save dialog). Is this possible? I've tried this: ...
4
1591
by: Tone Curtis | last post by:
I have a set of webforms where I need to prompt the user to "Save Changes". I can handle this to a degree within the form but if the user presses the Back button or selects the Home button the data...
4
6639
by: markalroberts | last post by:
Hi, I wish to ask warn the user that there are unsaved changes (if there are) and allow them to cancel navigating away/closing the browser. Investigation leads me to believe the...
6
3320
by: NH | last post by:
How can I warn a user that their session has expired when they click on a button etc?
9
5043
by: tomblower | last post by:
Access 2000 fully updated Three PCs manage data held on a server. They each have a front-end mdb file linked to tables on the server and on each PC. A problem has arisen over the following line...
89
5949
by: Cuthbert | last post by:
After compiling the source code with gcc v.4.1.1, I got a warning message: "/tmp/ccixzSIL.o: In function 'main';ex.c: (.text+0x9a): warning: the 'gets' function is dangerous and should not be...
5
3218
by: zephron2000 | last post by:
Hey, I need to either: 1. View the page source of a webpage after it loads or 2. Save the webpage to my computer after it loads (same as File Save Page As)
2
2574
by: tshad | last post by:
I have a page with Trace.Warns statements in my Page_Load and functions that it calls, but it doesn't seem to work in a class that is defined on the same page. I am writing this in C# I am...
0
7265
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7171
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7388
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7545
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5692
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5095
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4751
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3240
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1605
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.