www.webdeveloper.com
Results 1 to 3 of 3

Thread: Browser close button event capture

  1. #1
    Join Date
    Jan 2010
    Posts
    3

    Question Browser close button event capture

    I am currently using onbeforeunload to show user a message 'click ok to save cancel to continue'

    Question..
    On browser close event, I do not want to show the message to user. Can you please help with how to check the browser close event.

    Other details..
    If user closes the browser, my ajax request is not getting executed and hence I am not able to save the data to database. Hence I am planning not to show the popup when user closes the browser.

    Thanks in advance...
    Sandip

  2. #2
    Join Date
    May 2003
    Location
    Between Baltimore and DC
    Posts
    3,579
    You need to hang the browser for 200ms after you make the Ajax request to make sure it is sent. With IE, you can make an image request
    Code:
    var img = new Image();
    img.src = "foo?exit=true";
    and that will make it to the server with no issues.

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint] | twitter | linkedin | http://www.pascarello.com

  3. #3
    Join Date
    Jan 2010
    Posts
    3
    Quote Originally Posted by A1ien51 View Post
    You need to hang the browser for 200ms after you make the Ajax request to make sure it is sent. With IE, you can make an image request
    Code:
    var img = new Image();
    img.src = "foo?exit=true";
    and that will make it to the server with no issues.

    Eric


    Thanks Eric for taking time to reply my query.


    One thing to add - The Ajax request is working on local system but not in SIT environment.

    I tried the solution in SIT environment as below, but it does not worked.

    prepareNCallAjaxUserPrefSave();
    var img = new Image();
    var today = new Date();
    img.src = "/images/icon_csv.gif";
    img.src = "/images/icon_csv.gif?requestParam="+today;

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles