www.webdeveloper.com
Results 1 to 3 of 3

Thread: unload function not working in Firefox and Chrome

  1. #1
    Join Date
    Mar 2014
    Posts
    2

    Post unload function not working in Firefox and Chrome

    Hi

    I am trying to handle window or browser close event with javascript to invalidate the session. Following is the code

    window.onunload = function(e) {
    e = e || window.event;
    var y = e.pageY || e.clientY;
    if(y < 0){
    //call to java class to handle session
    }
    }

    This snippet is working with IE but not in FireFox(version 23) and chrome(Version 33)

    I tried onbeforeunload function which is working for all browsers but it is invoking even for refresh also which i don't require.

    Please suggest me to accomplish this issue..

    thanks inadvance

  2. #2
    Join Date
    Mar 2005
    Location
    Behind you...
    Posts
    966
    Playing with any unload scripts will typically leave you disappointed. Browsers all like to handle these sorts of things differently and there are a ton of restrictions.

    But if you insist on using the events then I'd suggest taking a look at the pageHide event for Firefox and Chrome. You'll want to add a check to make sure the event is supported, and then probably use the addEventListener (and attachEvent for IE8 and lower) to actually assign the event rather than directly assigning it to the window's event object.
    "Given billions of tries, could a spilled bottle of ink ever fall into the words of Shakespeare?"

  3. #3
    Join Date
    Mar 2014
    Posts
    2
    Quote Originally Posted by Sup3rkirby View Post
    Playing with any unload scripts will typically leave you disappointed. Browsers all like to handle these sorts of things differently and there are a ton of restrictions.

    But if you insist on using the events then I'd suggest taking a look at the pageHide event for Firefox and Chrome. You'll want to add a check to make sure the event is supported, and then probably use the addEventListener (and attachEvent for IE8 and lower) to actually assign the event rather than directly assigning it to the window's event object.
    I tried like below but still this pagehide not working in FF and Chrome

    window.addEventListener('pagehide', exit, false);
    function exit() {
    //submitting form to java application
    }

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