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

Complete save operation when popup is closed

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???
Jul 14 '08 #1
6 2227
hsriat
1,654 Expert 1GB
Can you explain with the help of some code what exactly are you trying to achieve?
Jul 14 '08 #2
acoder
16,027 Expert Mod 8TB
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!
Jul 15 '08 #3
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
Oct 3 '09 #4
acoder
16,027 Expert Mod 8TB
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?
Oct 6 '09 #5
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
Oct 6 '09 #6
Frinavale
9,735 Expert Mod 8TB
@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:

Expand|Select|Wrap|Line Numbers
  1. function PromptUserLogout(){
  2.   if(confirm('We have detected that you are leaving the page. Would you like to log out?'){
  3.     //make Ajax Request to server to log out user:
  4.     LogOut();
  5.   }
  6. }
You would configure the window to call this method during the onbeforeunload event:
Expand|Select|Wrap|Line Numbers
  1. window.onbeforeunload = PromptUserLogout;
Here's the Ajax code that will call the Logout ASP page (this page that should "release" your "locks"):
Expand|Select|Wrap|Line Numbers
  1. function LogOut() 
  2. {  /*  Instantiating the HttpRequest object that will be used to make the Ajax calls.  
  3.        See http://www.w3.org/TR/XMLHttpRequest/ for more information on this object.*/
  4.   var xmlHttp;   
  5.   xmlHttp=GetXmlHttp();
  6.  
  7.   /*  Logout.asp is an ASP page has been created for the sole purpose of logging out the user and releasing the "locks".*/
  8.   xmlHttp.open('GET', "http://localhost/Logout.aspx", true); 
  9.   //making the request
  10.   xmlHttp.send(null); 
  11. }
  12.  
  13. function GetXmlHttp()
  14. {   /*This function is responsible for creating an HttpRequest object 
  15.       based on the browser that the user is currently using. */
  16.   var xmlHttp = null;            
  17.   try
  18.   {   //Mozilla, Opera, Safari etc.
  19.     xmlHttp=XMLHttpRequest();
  20.   }catch(e)
  21.   {   //Internet Explorer uses ActiveX objects to make Ajax calls.
  22.       //the following are valid versions, here we will loop through 
  23.       //the versions and attempt to create the ActiveX that matches the browser.
  24.     var versionIds = ["Msxml2.XMLHTTP.6.0","Msxml2.XMLHTTP.5.0",
  25.         "Msxml2.XMLHTTP.4.0","Msxml2.XMLHTTP.3.0", 
  26.         "Msxml2.XMLHTTP.2.6","Microsoft.XMLHTTP.1.0", 
  27.         "Microsoft.XMLHTTP.1","Microsoft.XMLHTTP"];
  28.     for(var i=0; i<versionIds.length && xmlHttp == null; i++) 
  29.     {
  30.       xmlHttp = CreateXmlHttp(versionIds[i]);
  31.     }
  32.   }
  33.   return xmlHttp;
  34. }
  35.  
  36. function CreateXmlHttp(id) 
  37. {   /*Creates an ActiveX object used by Internet Explorer that will make Ajax calls*/
  38.     var xmlHttp = null;
  39.     try 
  40.     {
  41.       xmlHttp = new ActiveXObject(id);
  42.     }catch(e) {}
  43.     return xmlHttp;
  44. }
-Frinny
Oct 6 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

13
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,...
3
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...
23
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...
2
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...
7
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...
9
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...
5
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()) {...
2
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...
7
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. ...
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...
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
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
tracyyun
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...

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.