hello!
how can the save task be completed when the popup is closed in javascript.
for eg i have this save function. so when i click on the OK of confirmation dialog box , the popup should also close and the save task should be completed.i am working with asp.
even if i use onunload or unbeforeunload it doesn;t work
any suggestions???
6 2227
Can you explain with the help of some code what exactly are you trying to achieve?
I've changed the thread title. Avoid words such as help. Please remember to provide a meaningful Title for any threads started (see the FAQ entry Use a Good Thread Title).
This helps to ensure that other members, and also the general public, will have a better chance of finding answers to any similar questions. Thanks!
I think I have a similar problem. I've come to the conclusion that "onbeforeunload" is implemented in a very stupid fashion. Here's my problem-
I want to warn the user about leaving the page that they are on. I can use:
window.onbeforeunload = function() { return "WARNING" }
to do this. So the user gets a requester. So far so good. If the user clicks "CANCEL", I'm OK, because they go back to the page. The problem is that if the user clicks "OK", I get an immediate unload. I need to send a message back to my app saying that the user is closing the page! There should be a way to execute code AFTER the onbeforeunload event but BEFORE the unload event. The least they could have done is provided us some way to react to the "navigate away" event once it happens!
Any ideas?
gwalborn
That's what the onbeforeunload event is for. In fact, not all browsers support the event. Why would you need to let your application know immediately? You could use a timeout to cancel a session if that's the problem. Why can't you do it the other way round, i.e. let your app know the user is leaving the page and if the user is still on the page later, cancel/reset/ignore it?
I can't use a timeout because there may be times when the user does NOT interact for long periods and yet need to stay active. On the other hand, I need to release locks as soon as possible when the user DOES disconnect. As to doing it the other way around, if I release the locks and THEN find out that the user is still there, I cannot re-acquire the locks.
BTW, I found an answer to my problem. The problem with unload is that my page is gone and so I couldn't SUBMIT the page w/ a variable set to indicate that the page was unloaded improperly. I solved that by crafting a NEW url (GET) that signals my app that the page was unloaded illegally and loading that in a NEW window with window.open().
I still say that "onbeforeunload" is implemented strangely. It is highly counter-intuitive.
gwalborn
@gwalborn
I don't understand what the problem was...
You should have written a method that sends an Ajax request to the server when the user is leaving the page and if the click "ok".
It's not that hard.
You would have had to create a method that asks the user if they want to log out because they are leaving the page: -
function PromptUserLogout(){
-
if(confirm('We have detected that you are leaving the page. Would you like to log out?'){
-
//make Ajax Request to server to log out user:
-
LogOut();
-
}
-
}
You would configure the window to call this method during the onbeforeunload event: - window.onbeforeunload = PromptUserLogout;
Here's the Ajax code that will call the Logout ASP page (this page that should "release" your "locks"): -
function LogOut()
-
{ /* Instantiating the HttpRequest object that will be used to make the Ajax calls.
-
See http://www.w3.org/TR/XMLHttpRequest/ for more information on this object.*/
-
var xmlHttp;
-
xmlHttp=GetXmlHttp();
-
-
/* Logout.asp is an ASP page has been created for the sole purpose of logging out the user and releasing the "locks".*/
-
xmlHttp.open('GET', "http://localhost/Logout.aspx", true);
-
//making the request
-
xmlHttp.send(null);
-
}
-
-
function GetXmlHttp()
-
{ /*This function is responsible for creating an HttpRequest object
-
based on the browser that the user is currently using. */
-
var xmlHttp = null;
-
try
-
{ //Mozilla, Opera, Safari etc.
-
xmlHttp=XMLHttpRequest();
-
}catch(e)
-
{ //Internet Explorer uses ActiveX objects to make Ajax calls.
-
//the following are valid versions, here we will loop through
-
//the versions and attempt to create the ActiveX that matches the browser.
-
var versionIds = ["Msxml2.XMLHTTP.6.0","Msxml2.XMLHTTP.5.0",
-
"Msxml2.XMLHTTP.4.0","Msxml2.XMLHTTP.3.0",
-
"Msxml2.XMLHTTP.2.6","Microsoft.XMLHTTP.1.0",
-
"Microsoft.XMLHTTP.1","Microsoft.XMLHTTP"];
-
for(var i=0; i<versionIds.length && xmlHttp == null; i++)
-
{
-
xmlHttp = CreateXmlHttp(versionIds[i]);
-
}
-
}
-
return xmlHttp;
-
}
-
-
function CreateXmlHttp(id)
-
{ /*Creates an ActiveX object used by Internet Explorer that will make Ajax calls*/
-
var xmlHttp = null;
-
try
-
{
-
xmlHttp = new ActiveXObject(id);
-
}catch(e) {}
-
return xmlHttp;
-
}
-Frinny
Sign in to post your reply or Sign up for a free account.
Similar topics
by: dave yan |
last post by:
hi,
i have some forms which use javascript for data validation, e.g.,
checking to make sure all required fields are completed, checking that
data falls within valid ranges for certain fields,...
|
by: Kiki |
last post by:
Hello,
i wonder if anyone can help..
Is there a way of knowing from the parent window (var window;) that
the child window (var newWindow) has been closed? i can't touch the
child window's closed...
|
by: Markus |
last post by:
Hi,
i have this problem:
Sometimes, i can't reproduce, if i click on an small image on the
website, the popup _AND_ an other Tab in firefox open.
Here are the linkcode:
<div...
|
by: NWx |
last post by:
Hi,
I have the following question:
I have an app that uses user login/logout to identify users
When user logon, I register logon time in a session variable
When user logoff using the logout...
|
by: theyas |
last post by:
How can I get my code to NOT display two "Open/Save/Cancel/More Info" dialog boxes when using the "Response.WriteFile" method to download a file to IE
I've asked about this before and didn't get a...
|
by: tshad |
last post by:
This is from my previous post, but a different issue.
I have the following Javascript routine that opens a popup page, but doesn't
seem to work if called from an asp.net button. It seems to work...
|
by: praveen |
last post by:
Hi,
I am using nested resultsets to execute queries on two different
tables.
The code structure is:
stmt1 = conn.createStatement();
rs1 = stmt1.executeQuery(query1);
while (rs1.next()) {...
|
by: barthelemy.von.haller |
last post by:
Hi all,
I googled and read this group but could not find any solution to my
problem.
I have a page to download big excel files that we 'build' on the
server side. When a user click on the...
|
by: Kaster |
last post by:
I am using the script below on several webpages, to pop up a window where people can order some things. It works well when shifting forth and back between the same page from where it is activated. ...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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: 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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |