Detecting when user closes browser or moves to another site

How can detect when a user has closed the browser or moved to another website

No, it doesn't automatically fire any request to the server or so. Best what you can do at the server side is intercepting the session destroy using HttpSessionListener. You can also let Javascript fire a (ajaxical) request to the server side notifying that the onunload/onbeforeunload has occurred.
Difference between onunload and onbeforeunload is by the way that the onbeforeunload can still prevent the page actually being left using a warning message like "are you sure to leave page?" and that it is NOT supported by w3 specification and thus not guaranteed to be supported in all webbrowsers (as far under each Opera -which very strictly follows the standards- doesn't support it).
Edited by: BalusC on 25-aug-2009 11:04

Similar Messages

  • Call JavaScript when user closes browser containing webcenter

    Hi
    Scenario:
    1. Webcenter is opened in a browser.
    2. User closes the browser
    Requirement:
    - When user closes browser containing webcenter, a java script (or a servlet) should get called.
    As you know, we can call a script in 'onunload()' of body tag.
    But how do we call it with webcenter?
    Thanks.
    Edited by: 873687 on Dec 14, 2011 5:34 AM

    Here is a few links that I found for the JavaScript side you might play aroudn with.
    http://developer.irt.org/script/1230.htm
    http://www.webreference.com/js/tutorial1/reference.html
    http://www.experts-exchange.com/Web/Web_Languages/JavaScript/Q_20953676.html
    http://www.devguru.com/Technologies/ecmascript/quickref/window.html
    And two in German
    http://www.uni-magdeburg.de/service/www/books/muenz/javascript/objekte/window.htm
    http://www.exine.de/clientseitig/js_work_events.htm

  • How to capture when user closes browser

    I am implementing a scenerio where I need to reset login status in the database to false when a user closes browser without logout. I am at fix, how do I do that ????? With the java script solution, its a browser dependent and may not work with all the browser. With java sessionListener, the sessionDestroyed() method is never called when browser is closed.
    Plz. help... how can I capture the browser closing event. My application is running on Websphere and integrated with active directory for authentication and authorization.
    Thanks in advance......

    SoulTech2012 wrote:
    what about HttpSessionBindingListener?
    javascript solution doesn't sound good to me"hack" was chosen for that reason. Currently, there are no real good solutions for this. The browser runs autonomously from the server so there is not a lot that can be done. HttpSessionBindingListener is intriguing but I bet when the browser is x'd out of there is nothing sent to listen to.
    The first reply "reasonable timeouts" is the most relied on solution. All others are a lot of work for iffy pay back at best. This is one of the issues that has forced me into rather strict no session solutions.

  • Releasing table locks when user closes browser

    Hi, I've read the blogs and tried some of the code that people have suggested but it just never seems to work.  I have locked table entries belonging to a stateful 2003 BSP.  The user closes the browser by means of the 'X' and the table locks remain.  I have table lock releases in the 'OnDestroy' event but that never seems to occur.  I have tried inserting JavaScript to capture the closing of the window but either it captures every other event or it gets confused when navigating to another page.  I have the redirect examples however they all seem to be part of a proper logoff procedure, rather than the cowboy approach of just shutting down the browser.  There must be a simple procedure out there to do this.  Is there a complete example somewhere?
    Any help will be appreciated,
    Kevin

    Hi Raja, ok I discovered why it isn't working and it really is quite obvious.  The browser that it's being tested on has a Google toolbar installed. Among other things this toolbar allows users to block the display of popups.  If this is selected the script will not run properly as it needs the alert to allow the server side to run.  This is going to be frustrating because while most of the user's desktop is managed by the corporation they still have the ability to add toolbars to their browsers and configure them, and I'm sure most people will select the popup blocker. 
    Kevin

  • From a new ipad user: if I'm listening to live radio, how do I switch it off to move to another site without switching off the ipad?

    From a new iPad user: if I'm listening to live radio, how do I switch it off to move to another site without switching off the iPad?

    If you're listening to radio from the app, you need to go to that App (press Home button twice for multitasing menu and tap on its icon), and stop it there. If there is no such feature - you can "kill" the app, open multitasking menu again, hold one of the icons for couple of seconds, and click "X" symbol next to the radio app.
    If the radio streams in Safari (web browser), you can simply stop it by closing the tab - tap little "X" next to the tab where the radio is playing.
    Hope this helps

  • Record locks created when user closes the Browser and not the Web Form

    Hi. We sometimes encounter the issue where a user updates a record, locking the record on the table, but then they unexpectedly closes the browser without saving by clicking the X in the upper-right of the browser window. Then when another user comes along and attempts to edit that record they get the message Unable to Reserve Record. The orphaned record lock eventually does seem to clear itself out, but that can often take 15-20 minutes.
    Is there any way to speed this up? Or to pragmatically keep this from occurring? Either on the database side or with some code in a particular application?
    Please let me know your thoughts. Thanks in advance.

    If a user closes the browser window the forms runtime on the application server holding the locks is in most cases still up and running. The FORMS_TIMEOUT controls on how long a forms runtime on the server is up and running without the client applet not sending a heartbeat (See MOS note 549735.1). By default this is 15 minutes which would explain your locks being held 15 minutes.
    You could decrease the FORMS_TIMEOUT in the default.env, so the forms runtimes get cleaned earlier and thus the locks get released earlier.
    Note that if you have blocking client_hostcalls with webutil this might be a problem, as it prevents the forms applet from sending the heartbeat and after the FORMS_TIMEOUT passed while the forms applet is blocked the forms runtime on the server gets closed.
    cheers

  • Show Confirmaiton Dialog when user closes the browser

    Hello All,
    Can we show a confirmation dialog when user chooses to close the browser in which applet is running? I know that it can be done using javascript. Can it be done using java code?
    Please suggest.
    Thank you.

    teejrama wrote:
    ..Can we show a confirmation dialog when user chooses to close the browser in which applet is running?.. You can pop a JOptionPane in the applet's destroy() method, but that will not do any good, since the browser is not asking the applet for advice on whether it is closing, it is telling the applet it is closing.
    ..I know that it can be done using javascript... Can it? How?
    If so, that would be another good reason to disable JS.
    ..Please suggest.I suggest you presume the end-user is smart enough to know when they want to close their own browser, and not interfere in that process.
    Thank you.No worries.

  • Trigger events when user closes a Web Form?

    Hi. Is there a way to fire code (a trigger perhaps?) when a user unexpectedly closes the entire browser window by clicking on the X in the upper, right corner of the browser?
    Or, is there a way to prevent the user from being able to close the browser window by clicking on the X?
    Any help would be great. Thanks.
    Edited by: sharpe on Jun 26, 2012 11:20 AM

    The concepts behind a running form tend to be a mystery for some. However, there is no reason to believe that any Oracle magic occurs when running an Oracle Forms application. On the client side, the running for is a standard java applet. Like any applet running in a browser, the browser uses a plug-in (the JRE in this case) to support the content (the applet). The browser creates a container on the page where the JRE can present its content or host the applet, based on the underlying html. Once the applet starts, it will be displayed in this container space on the page within the browser window. In the case of Oracle Forms, we decided it would be nice to offer an option where the form could be exposed outside of this browser space and float freely.
    So the answer to your question regarding what the "window" is called, well the browser is the "browser" and the floating window is actually a java frame which can be created in any applet. Again, no Oracle magic here. ;)
    Generally, separateFrame=true is used when more real-estate is needed or when you simply do not want to see the browser controls. That said, I often recommend against using separateFrame=true for a variety of reasons. One of the most common reasons is that if the browser window which is hosting the form is closed or if the browser navigates from the current page, the running form will terminate. Because the browser, in this case, is not doing anything obvious, end-users can easily make the mistake of thinking it is ok to navigate to a webpage using the currently shown blank page. This will cause the form to close.
    If you don't mind having the browser controls visible then using separateFrame=false is probably a better way to go. This would also allow you to use the note I mentioned in order to detect attempts to close the browser, assuming you are using Forms 10.1.2.3 or newer and JRE 1.6. To detect the closing of the "separateFrame" you likely would need to create a java bean, which may become a little more complicated than what can be described here. But remember what I mentioned above, if you use separateFrame=true and the hosting browser is closed, the form will also close. So in this case, you would have to code to detect both the applet frame closing as well as the browser window.
    There are a variety of ways in which some of the browser controls can be hidden using java script, so this can offer some help if using separateFrame=false. So this is yet another option.

  • Session does not end even when i close browser

    when i close firefox/IE the session continues ,What i need is that i am adding amount in shopping cart ,but the amount adds to old amount even when i open a new browser window ,
    i hv checked that my browser will remove cookies when i will close mozilla
    i hv also printed total=0 in servlet's ini method but the init method is called only once and total does not reset to 0,does 'th the call to init method is made everytime we start a new session via browser ,it does not get called whn i close the current browser and open new one.how to destroy the older servlet?
    I m using s=request.getSession()
    and s.setAttribute("billamnt",total)
    the code of the servlet is
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    public class addtocart extends HttpServlet
         HttpSession s;
         PrintWriter pw;
         int total,cam,mob;
         public void init()
              total=0;
              cam=0;
              mob=0;
              System.out.println("inside  cart init");
    public void service(HttpServletRequest req,HttpServletResponse res) throws IOException
         s=req.getSession();
        res.setContentType("text/html");
         pw=res.getWriter();
         pw.println("<html><body><a href="+"mobs"+">Mobile</a><br><a href="+"cams"+">Camera</a><form method = "+"post "+"action ="+"bill"+"><br><input type= "+"submit"+"></form></body></html>");
        if(req.getParameter("csony")!=null)
        cam=cam+Integer.parseInt(req.getParameter("csony"));
        if(req.getParameter("clg")!=null)
        cam=cam+Integer.parseInt(req.getParameter("clg"));
        if(req.getParameter("cnokia")!=null)
        mob=mob+Integer.parseInt(req.getParameter("cnokia"));
        if(req.getParameter("cerricson")!=null)
        mob=mob+Integer.parseInt(req.getParameter("cerricson"));
        s.setAttribute("cambill",new Integer(cam));
        s.setAttribute("mobbill",new Integer(mob));
        s.setAttribute("billamnt",new Integer(cam+mob));
    public void doPost(HttpServletRequest req,HttpServletResponse res)
    public void doGet(HttpServletRequest req,HttpServletResponse res)
    }Wats the problem?
    Message was edited by:
    pooja_k_online

    The servlet is not created on a session basis. All users share the same servlet object. The servlet is created once when the servlet is first called in the context, then is maintaned until the server shuts down.
    You should not store any state in the servlet. You should use the HttpSession object you get from the request object to store the totals, and all other values. You should not use the servlet to hold on to a session object, as multiple users would see the SAME session that way. If you need to use the session in multiple methods, then you should pass that object as parameter, not by making it a class member.
    You also shouldn't put the work in the service method of the HttpServlet. You should put it in either the doGet or doPost method (and if you want to make it happen for both type requests, call doPost from the doGet method and put the work in the doPost method).
    For example:
    public class ShoppingCartServlet extends HttpServlet {
      public void doGet(HttpServletRequest request, HttpServletResponse response) {
        doPost(request, response);
      public void doPost(HttpServletRequest request, HttpServletResponse response) {
        HttpSession session = request.getSession();
        Integer cambill = (Integer)session.getAttribute("cambill");
        int cam = 0;
        if(cambill != null) cam = cambill.intValue();
        Integer mobbill = (Integer)session.getAttribute("mobbill");
        int mob = 0;
        if(mobbill != null) mob = mobbill.intValue();
        Integer billamnt = (Integer)session.getAttribute("billamnt");
        int total = 0;
        if(billamnt != null) total = billamnt.intValue();
        String csony = request.getParameter("csony");
        if (csony != null) cam += Integer.parseInt(csony);
        String clg = request.getParameter("clg");
        if (clg != null) cam+= Integer.parseInt(clg);
        String cnokia = request.getParameter("cnokia");
        if (cnokia != null) mob += Integer.parseInt(cnokia);
        String cerricson = request.getAttribute("cerricson");
        if (cerricson != null) mob += Integer.parseInt(cerricson);
        total = cam + mob;
        session.setAttribute("cambill",new Integer(cam));
        session.setAttribute("mobbill",new Integer(mob));
        session.setAttribute("billamnt",new Integer(total));
        PrintWriter pw=response.getWriter();
        pw.println("<html><body><a href="+"mobs"+">Mobile</a><br><a href="+"cams"+">Camera</a><form method = "+"post "+"action ="+"bill"+"><br><input type= "+"submit"+"></form></body></html>");
        pw.close();
    }Message was edited by:
    stevejluke

  • Ending session when user closes window w/o logging out

    Hi,
    I tried looking everywhere for a solution to this problem and was unable to do so. I'm running tomcat 4.0.5 on win2k and am trying to prevent multiple user logging capability, but the listeners that I implemented for the session can only detect the creation of the session, and the destruction after the pre-set session invalidation time. So if the user closes the window 15 minutes into the session, the server still has the flag for "logged in" in place and the user cannot log in for the remainded of the session time (which is another 15 minutes).
    Can anyone please help me with this problem?
    Thank you very much,
    Lior

    How can I do that? Do you have any code I could take a look at. Thanks a lot.

  • Force end of session when user closes window without logging out

    I want to protect sensitive employee data. Does anyone know how to force a user's portal session to be terminated after a user closes a window with the "X" instead of logging out?

    Web application is connectionless. So there is no way to tell if a user has disconnected. If the user diligently logout, then invalidating a session is no problem. However, if you wish to invalidate the user upon closing of window, I suggest you drop that idea and change to different approach.
    1. If you are trying to impose single logon policy, you may consider invalidate an existing session if the same user login again.
    2. If you really need to invalidate a user session as soon as he is inactive (or closes window). I suggest you set a very small timeout interval (maybe 3 minutes). Then for all the pages, implement a simple invisible IFRAME that will keep refreshing itself (say every 2 minutes) on a dummy JSP/servlet URL. The fact that this IFRAME always hit the URL at 2 mins interval will keep the user session valid. Once the browser window is closed, the session will be invalidated in max 3 mins time.
    The final suggestion is to drop that idea altogether, the point is ... implement such feature is like twisting web application to do something that it is not design to do naturally.

  • Detect when user stops scrolling

    I have an application where a user scrolls using scrolldrags, but this always ends up in the user clicking where they stopped scrolling, so I need to stop this. My idea was that I have a variable "changeable" on and off depending on whether the user is scrolling or not, so when they stop scrolling, the objects become changeable again, how do I detect when the user stops scrolling with scrolldrag using the ScrollPane object?

    add a mouseup listener when scrolling begins and apply a stopPropagation() or stopImmediatePropagation() method to that event and remove the listener in the mouseup listener function .

  • Detect when User Calc Script is Finished

    We are looking for a way to detect when a user has finished a calc script before defragment. We have a windows batch file which defrags multiple times during the day. Before we defrag we want to make sure all users are done running calc scripts. After this we want our defrag to begin. Likewise if the system is busy we want the defrag to wait until the user is done.

    A simple way is to unload the application UNLOADAPP "SAMPLE"; or ALTER SYSTEM UNLOAD APPLICATION SAMPLE; in Maxl. If a calc is running or the database is busy in any way, then the unload will fail with an error message telling you who is still performing an action on the database. If the action is succesful, then the application is quiet. You then disable connections to the application immediately to prevent anyone logging in, then do your defragment. Unloading the application at the end will automatically re-enable connections.

  • Detecting when users connect/disconnect

    I have a client application that communicates via EJB and also
    subscribes to JMS topics. I need the server to programatically
    detect when a client connects and to JMS and when they go away.
    We want to keep course grained stats on how long someone is connected.
    The WebLogic console shows when a user is connected and it their
    name goes away when they disconnect - I don't want
    to pay someone to stare at the console window with a stop watch
    and time connections.
    How can I programmatically detect when clients connects and
    disconnects?

    That may be a good idea but what are we supposed to do in the meantime.
    any work arounds etc??
    Gary Keim wrote:
    I think that in general the BEA people watching these newsgroups are
    developers and developers don't have the authority to issue product-related
    announcements. The best way for you to be heard is via a sales
    representative.
    Now, the way I think this should be done in the future is via JMX. The JMS
    service will have a public RuntimeMBean that you could access and to which
    you would add yourself as a listener. Then it's standard JavaBean property
    change notifications.
    Gary
    "Larry Presswood" <[email protected]> wrote in message
    news:[email protected]..
    Yes and no-one from BEA is picking this issue up either.
    Mark Steele wrote:
    This is the only message I've seen about this.
    Odd. I would think that more people would want to know
    stats on connections...(?)
    Larry Presswood <[email protected]> wrote:
    This is a big issue did you get any replys from the BEA
    folks or anyone
    else.
    Used to you could use workspaces or events but those have
    been depracated
    in
    6.0
    Mark Steele wrote:
    I have a client application that communicates via EJBand also
    subscribes to JMS topics. I need the server to programatically
    detect when a client connects and to JMS and when theygo away.
    We want to keep course grained stats on how long someoneis connected.
    The WebLogic console shows when a user is connectedand it their
    name goes away when they disconnect - I don't want
    to pay someone to stare at the console window with astop watch
    and time connections.
    How can I programmatically detect when clients connectsand
    disconnects?

  • Detecting when user clicks title bar of TitleWindow

    I am just beginning to dabble in Flex and am loving it so
    far. I can't seem to figure out how to detect when a user clicks
    the title bar of a TitleWindow. Could someone please give an
    example of the correct way to detect this? How do you tell the
    application to dispatch an event only when the title bar is clicked
    and not the contents of the TitleWindow.
    Thanks!
    Josh

    Subclass TitleBar and add a mouseDown event handler to the
    protected titleBar property (of type UIComponent). That event
    handler will execute when a person clicks down in the header.
    Stephen

Maybe you are looking for

  • Why does "Make Work Path" give crummy paths?

    I don't use Photoshop much, so I bet I'm missing something obvious. Lately I've been drawing hollow elipses on top of existing photos, with crummy results. I have been making a selection and stroking the selection (should I be doing it something diff

  • About Live stream with FMS

    Hi, I am doing somthing FMS.I download the FMS4 and Adobe Flash Midea Encoder3.5 here. Installed to my PC,they are working without any configure. and now I want to develop a client base on gstreamer to play the RTMP:// videos. My client play VOD vide

  • English language of FMw 11gR2

    Hello Is it possibile when Installing FMw 11gR2 (setup.exe) can I get English language of Builder? In setup.exe -help I don't see var Lang, I have 2 PC one with SO in english and it's ok, the other is Italian(I don'understand it) and I want english,

  • When opening firefox the search bar is off centre

    the search bar is off centre and further to this when i go to another site, that what is displayed is off centre as well

  • What is the correct installation sequence for my ATI Radeon 9800 PRO MAC AGP 128MB into my Quicksilver 867 G4?

    Hi. I just got my used ATI Radeon 9800 PRO MAC AGP 128MB card. What is the correct installation sequence into my Quicksilver 867 G4 running 10.4.11 on one drive 10.5 on another? The original NVIDIA GeForce2 MX - 32MB SDRAM went bust. Is the driver bu