Complete save operation when popup is closed

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • thesinnerishere
    New Member
    • Jul 2008
    • 6

    #1

    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???
  • hsriat
    Recognized Expert Top Contributor
    • Jan 2008
    • 1653

    #2
    Can you explain with the help of some code what exactly are you trying to achieve?

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      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!

      Comment

      • gwalborn
        New Member
        • Oct 2009
        • 2

        #4
        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.onbefore unload = 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

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          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?

          Comment

          • gwalborn
            New Member
            • Oct 2009
            • 2

            #6
            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

            Comment

            • Frinavale
              Recognized Expert Expert
              • Oct 2006
              • 9749

              #7
              Originally posted by gwalborn
              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.onbefore unload = 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
              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:

              Code:
              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:
              Code:
              window.onbeforeunload = PromptUserLogout;
              Here's the Ajax code that will call the Logout ASP page (this page that should "release" your "locks"):
              Code:
              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

              Comment

              Working...