473,386 Members | 1,745 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,386 software developers and data experts.

Exc something on OK from onbeforeunload

window.onbeforeunload = function() {
if (x == false){
return "Is it ok?";
}

This piece of code let users of my intranet to not exif accidentally
from yhe page.

I would also, after they have clicked "Ok" (and then exit from window),
exec some code (in particular I have to save in a db an Id value of user.)

Is it possible?

Any help appreciated.

Regards.

--
Fabri
-Mandrake "A Poma', c'hai 'na faccia...!"
-Pomata "Sì, se ce n'avevo due già stavo all'università... sotto
spirito!"
Jul 23 '05 #1
3 1723
VK
> I would also, after they have clicked "Ok" (and then exit from window),
exec some code (in particular I have to save in a db an Id value of user.)


Save on server or on client?

Jul 23 '05 #2
VK wrote:
Save on server or on client?


On server, obviously ;-)

Something like this (but it doesn't work)
window.onbeforeunload = function() {
var msg = "===============================================\n \n\n";
msg+= "For security reason exiting from this page will cause you
cannot enter anymore in this url because of uniqueness of this action.
Continue?\n\n\n.";
msg+= "============================================= ==";
return msg;

// If "OK" will be clicked then I have to save informations.

}

Thx.
--
Fabri
-Mandrake "A Poma', c'hai 'na faccia...!"
-Pomata "Sì, se ce n'avevo due già stavo all'università... sotto
spirito!"
Jul 23 '05 #3
VK
> Something like this (but it doesn't work)
window.onbeforeunload = function() {
var msg = "===============================================\n \n\n";
msg+= "For security reason exiting from this page will cause you
cannot enter anymore in this url because of uniqueness of this action.
Continue?\n\n\n.";
msg+= "============================================= ==";
return msg;

// If "OK" will be clicked then I have to save informations.
}


If OK clicked then the browser gets closed. Otherwise it would be too
easy to create non-closable windows - on each onclose it would just run
another long process.
You cannot do anything really reliable with JavaScript (except setting
up cookies, what wrong with it by the way?).

Usually one goes from the opposite direction: upon login server creates
user's session file. On each call (step 1, 2, 3, n) server updates the
session file, so it always keeps the state of the last *successfull*
operation. This way your users can close the window, press computer
reset button, pull coffee inside the system block, dance lambada on
keyboard, yours to continue... But the session info is always secured
on the server.

Otherwise:

window.onbeforeunload = function() {
// try to save session info
// in hope that you'll get your chance for it
}

Jul 23 '05 #4

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

Similar topics

4
by: lltaylor | last post by:
Hello, Currently I use an onbeforeunload method, to do call various tidy up methods when a user exits my web application - however I now need to add additional support, for users migrating to...
6
by: jennyw | last post by:
Hi, I'd like to use onbeforeunload to submit a form before leaving a page. This works in Firefox and IE. Safari, however, blithely ignores this. Does anyone know of a workaround for Safari? Or...
4
by: sowencheung | last post by:
the bug of onbeforeunload is so obvious! in IE 6 it will popup twice "sometimes" I am using the following code window.onbeforeunload = null; window.onbeforeunload = confirmExit; var...
8
by: drewmania001 | last post by:
im currently using the following to prompt the user before navigating away from the page // add an unload event window.onbeforeunload = bunload; // function to prompt user function...
6
by: hemant.singh | last post by:
Hi all, I am trying to get a way by which I'll know exactly when user goes out of my site by clicking on close button in browser, So that w/e user click close button in browser, I can send a...
1
by: David | last post by:
I am using a process to warn users when they leave a page that there have been changes made. I took the example directly from Microsoft example I found in searching for help on the event...
1
Frinavale
by: Frinavale | last post by:
Introduction I've seen many questions asked about how to disable the browser's back button and in the past I've replied with "it's simply not possible". It's not a good idea to disable the back...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...

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.