views:

27

answers:

2

I have a dialog window in my JSP page and its implemented using jQuery.

If my server is timed-out and I click on a button to open the dialog window, my login-page is shown inside the dialog window.

I want to actually close the dialog window and redirect to login page.

How can I achieve this?

A: 

I think what you would need to do in this situation is to create a global function that allows you to "breakout" of the dialog (which I am assuming will use an iframe...). So for instance, in your JSP page, you could create a function such like:

FrameBreakout = function(url) {
  document.location.href = url;
};

And when you render the response for the login page, do something similar to:

if (parent && parent.FrameBreakout)
{
  parent.FrameBreakout("/login.jsp");
}

When that code executes within the iframe (that's why we check for the parent object first) it will cause the outer document to redirect.

That's just a template really, but should lead you in the right direction...

Matthew Abbott
+1  A: 

Assuming what you are asking is that when you click a link a jquery dialog window opens, or it will redirect you to the login page:

You could have the login link button like so:

 <a href="loginURL">Login</a>

then in the javascript:

  $("a").click(function() {

       if (code to determine if server is not timed-out)
            $("selectorForDialog").dialog({ options });
            return false;
       }
  }

if the server is not timed-out, it will open the dialog, else it will go to the url specified by href in the <a> link

http://jqueryui.com/demos/dialog/

Joey C.
I tried this, but due to some different style of implementation was not able to check like this so I used, jquery-idleTimeout.js: More info on it can be found @http://philpalmieri.com/2009/09/jquery-session-auto-timeout-with-prompt/
Panther24