473,390 Members | 1,300 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,390 software developers and data experts.

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 18861
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
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
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
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
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
by: NH | last post by:
How can I warn a user that their session has expired when they click on a button etc?
9
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
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
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
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
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
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.