Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 20th, 2004, 03:39 PM
Registered User
 
Join Date: Feb 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to happydeveloper
Default browser close action commands

I capture a browser close action using the following code in an onunload option:

      var iX = window.document.body.offsetWidth + window.event.clientX ;
      var iY = window.event.clientY ;

      if (iX <= 30 && iY < 0 )
      {
         // code to do something
      }

How do I transfer control to another window or call a java method to handle logoff chores from my application?

Thanks for any help you can provide.



Steve Oliphant
 
Old February 20th, 2004, 04:50 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Quote:
quote:
How do I transfer control to another window?

Do you mean to cause another window to come on top?

onunload = surface;

function surface()
{
 opener.focus(); //to focus the opener
 child_window_name.focus(); //to focus a child window
}

Otherwise I'm confused...

----------
---Snib---
----------
 
Old February 20th, 2004, 05:51 PM
Registered User
 
Join Date: Feb 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to happydeveloper
Default

Let me explain the situation. I'm using a portion of Oracle JDeveloper for a web application which generates a standard J2EE application following the model - view - controller framework.

The technology is called UIX (stands for User Interface XML) and generates java code on the fly.

When a user logs on, I add their name to a java object which persists on the controller side which runs on the server.

If a user clicks on the application logoff button, all is well. If they just close the browser window, then they are left in a logged on state as far as the server is concerned and will remain that way until the server side is restarted.

The only way, apparantly, to capture a window close is to add a uix tag called <uix:body>. So the complete code block above looks like so:

   <uix:body onUnload="

      var iX = window.document.body.offsetWidth + window.event.clientX ;
      var iY = window.event.clientY ;

      if (iX #60;= 30 #38;#38; iY #60; 0 )
      {
         alert('Logging User Off');
         alert('User Logged Off');
      }

   ">

The funny stuff in the if statement are escape sequences so that I can have < and & symbols in the javascript code. I put in the alerts to prove the code was working when I closed the browser by clicking on the X.

So, I can catch the browser close, but now I want to somehow get the information back to the server side that the user is no longer active and should be logged off. I have a java class called SmartLogin with a method called handleLogoff that will do the trick. If there is a way to call it directly, that would be great.

Another way would transfer control to a special not-displayed uix page which could call the java routine above.

I just don't know how to do it.

Thanks for any help you can give.



Steve Oliphant
 
Old February 20th, 2004, 08:28 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Hey Steve,

I've been searching Google for a while, and found nothing.

However, I came up with this idea: on unload, cause a popup to come up that goes to logout.jsp (or whatever your logout page is, with the additional ?this=that&that=this if needed). Put your handleLogoff stuff (can you tell I don't know a thing about Java? :)) on that page. Then close the window immediately with JavaScript:

window.close();

So it would look like this:

-- page1.jsp --

<uix:body onUnload="

      var iX = window.document.body.offsetWidth + window.event.clientX ;
      var iY = window.event.clientY ;

      if (iX #60;= 30 #38;#38; iY #60; 0 )
      {
         alert('Logging User Off');
         alert('User Logged Off');
      }
      window.open("logout.jsp?this=that&that=this");
   ">

-- end page1.jsp --
-- logout.jsp --



<script language=javascript>window.close()</script>

-- end logout.jsp --

If the logout page prompts "This script is trying to close the window...", see the fourth post in this page.

I have a login script using PHP, it's lots easier than this. Closing the window ends the session. :)

Hope this helps you,

----------
---Snib---
----------
 
Old June 14th, 2007, 01:31 PM
Registered User
 
Join Date: Apr 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I've searched and searched for a way to capture the browser closing event and FINALLY there it is !!!!

function LogOff()
{
  var iX = window.document.body.offsetWidth + window.event.clientX ;
  var iY = window.event.clientY ;
  if (iX <= 30 && iY < 0 )
  {
     window.open("../LogOff.aspx")
  }
}






Similar Threads
Thread Thread Starter Forum Replies Last Post
Browser close when screen saver close Rehanrana Pro VB 6 1 April 7th, 2008 03:09 AM
How to close browser window? rupen Javascript How-To 14 July 31st, 2006 10:52 AM
trying to close browser in a button taliosfalcon ASP.NET 1.0 and 1.1 Basics 1 February 7th, 2005 12:11 AM
How to close a browser session ? elisabeth Pro JSP 2 April 11th, 2004 11:30 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.