admin管理员组文章数量:1415467
Here is the thing : my webapp has loads of popups and my boss wants 'em closed on session expiry, coz when session expires and an user presses refresh on a popup, he is being shown the logon page -> user logs on -> user is directed to the dashboard. Now, a dashboard screen in a popup is totally uncool. Here is where google got me:
Have javascript to close popup onload. Generate this onload script into the response if session has expired (checking session expiry from jsp and including onload script conditionally).
Do you think this is a good way to it? What is the best practice for this scenario?
P.S: I am not allowed to use AJAX
Here is the thing : my webapp has loads of popups and my boss wants 'em closed on session expiry, coz when session expires and an user presses refresh on a popup, he is being shown the logon page -> user logs on -> user is directed to the dashboard. Now, a dashboard screen in a popup is totally uncool. Here is where google got me:
Have javascript to close popup onload. Generate this onload script into the response if session has expired (checking session expiry from jsp and including onload script conditionally).
Do you think this is a good way to it? What is the best practice for this scenario?
P.S: I am not allowed to use AJAX
Share Improve this question asked Jul 28, 2009 at 1:42 JayJay 2,45411 gold badges60 silver badges101 bronze badges 4- 2 The best practice is to not use "loads of popups". That aside, when you talk about closing popup in "onload" event what would really happen is user would refresh the popup and it would close (which would be REALLY weird from user's standpoint) OR user would get a prompt from the browser (close this window? yes / no) which is equally weird. – ChssPly76 Commented Jul 28, 2009 at 1:51
- @ChssPly76 - yes, from an user standpoint, it's probably weird. But, designing data-oriented applications without pop-ups is one heck of a challenge. – Jay Commented Jul 28, 2009 at 1:54
- I'm ok with popups as long as I don't need any of the information behind it. If I do, I get pissed at them and curse the designers. – geowa4 Commented Jul 28, 2009 at 2:01
-
1
The only possible excuse for using popup windows is a requirement for application to function without javascript because then you can at least do some stuff via
<a href='...' target='...'
voodoo. Beyond that, everything you can do with popups you can do without them (via javascript windows, partial content updates, what have you). Now I can totally see where "not allowed to use AJAX" would put a cramp in that approach, so I'm not bashing your design choice per se, just the plete ridiculousness of the "design without popups is a challenge" statement :-) – ChssPly76 Commented Jul 28, 2009 at 2:30
5 Answers
Reset to default 1In a past life, I made a popup manager object that maintained what windows were open. You should probably make one of these if not already done. Then, you can use setTimeout
to call a function after so many minutes (or whatever time you want) have gone by. This will check for recent activity (probably via AJAX) and close the popup if you determine that the session has expired. If not, call setTimeout
again with your new time, properly adjusted for most recent activity.
^^before the AJAX edit.
Well, since you can't use AJAX, can you put something in the url that will tell you it's a popup? Then you'll know not to show the login screen when the user hits reload.
The best way would be an XMLHTTP request to check login and close them if required - do this periodically.
Astute readers (meaning everyone) will notice that this is an AJAX request, but if you phrase it that way it might get accepted as whoever dictated that you 'aren't allowed to use AJAX' is clearly an idiot.
An alternative way to implement modal dialogs in a web application is to:
- Model the dialog in a DIV, default styled to display: none;
- On desired action, inject/append the Modal dialog DIV into the page source
- Reset the CSS display so the modal dialog DIV is visible, overlaid on top of the page by setting the CSS z-index property
- Make the modal dialog disappear upon either successful execution or the user cancelling out
Because the modal dialog is part of the page source, the dialog will disappear when the session times out. This approach doesn't spawn supporting windows that can be orphaned as the poster is attempting to address. And it fits the requirement of not using AJAX.
You can code these by hand, but I don't really remend it because of having to support various browser. I suggest looking at the Yahoo User Interface. You can tailor it to suit your needs (IE: only modal dialogs), and it would support AJAX if requirements change down the road.
Beware of spawning modal dialogs from modal dialogs.
If your boss is asking you to achieve this, without using AJAX, then you're in trouble. He should understand that the only connection a browser has to the server (without refreshing the page) is javascript (what he understands to be ajax).
The best way to do this is to setup a script on the pages to ask the server if the user is still logged in every 30 seconds or so.
setInterval(function(){
$.get("loggedin.php", function(result) {
if (!result.isLoggedIn)
window.close();
});
}, 30000);
This script assumes you're using the jQuery framework for rapid development of javascript solutions. This also uses JSON (Javascript Object-notation) to test a return-value from the loggedin.php file.
Bottom line, you need to use AJAX. Tell your boss there is no other way. If he still doesn't get it, ask him to balance his checkbook without using math.
In theory, you could avoid AJAX by using a hidden flash widget...
But more practically, AJAX is the 'right' solution, and I think you will have to talk to your boss, determine where this 'no AJAX' rule came from, and convince him that AJAX is the best way to solve this problem.
Does he think AJAX would be take too much time to implement? If so, you should prove him wrong. Does he think it will be hard to maintain? If so, show how simple the code to do this will be, and how widely used the mon AJAX libraries are. If your boss is reasonable, then his goal is to what is best for the product, and you should be able to reason with him.
本文标签: javaClosing popups on session expiryStack Overflow
版权声明:本文标题:java - Closing popups on session expiry - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745230665a2648809.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论