I know this is almost the same question: ask by Joe
I have a web application. When I close the window (clicking X on browser) it will call the Logout functionality.
The problem is when I open the web application and open the same web application on different window (new window or another tab). And close one of the window it will call the Logout functionality even if there is still an open window for that application.
What I want to do is, check first if there are other window that is using the same jsessionid with the current window I am about to close. And when I close that window, It will only call the Logout functionality if there is no window using the same jsessionid.
The standard way of course would be to have the login cookie expire at browser close and thereby log you out, but I'm guessing this is not an acceptable behaviour in your case?
AFAIK you can't access the content of another browser window unless that window was created using Javascript. Since it sounds like you're using onUnload handlers in Javascript, you could make use of those same handlers to keep track of your windows. It would lead to some overhead though and would not be full-proof (would not handle browser crashes or if the user navigates away from your app for example).
Pseudo-code: (this needs to be a mix of server-side code and client-side javascript since the load handlers are handled in Javascript and the session is server-side)
function OnLoad() {
if (document.referrer != "{identify your app here}")
Session("BrowserWindowsOpen")++;
}
function OnUnLoad() {
if ({your code for if window is closed})
{
Session("BrowserWindowsOpen")--;
if (Session("BrowserWindowsOpen") == 0 )
performLogOut();
}
}
Related
I need to open a browser with URL and then wait till person clicks a special button. And if it happens, return true. Can I implement it with java tools or should I use javascript?
You should use JavaScript. Java is a Server side language, so all processing of Java code will be completed before the user has the chance to interact with the page. JavaScript (traditionally) works on the client-side and is commonly used to capture user interactions with the browser.
yes, Java Script or any frame work that builds on Java script like Jquery works for you. If understands you correctly,
create Hyper link
Browse the page that you needed
Place HTML button on the page, write onClick logic on that button to return true.
I have a Java applet that runs with no UI and sends XML back to the calling Javascript for processing to a database. I have the applet set up to do a callback once the applet is initialized using an Init override and the callback is a Javascript function that proceeds to do some work with another applet method.
If the user clicks the "No" button on Java security warning however, no applet code is ever run and the calling page waits forever for the callback to occur. Is there a way to trap the user declining the security warning in Javascript?
Please no questions on why I'm using an applet for this, it's a very complicated infrastructure (out of my control) which involves multiple web vendors and this is the only architecture I've found that meets all the other requirements.
About the best you can do is poll for the applet appearance in JS, and if it doesn't appear after a 'length of time', pop an alert to the user offering to redirect to help (or wait - if they are still looking over the details offered by the security dialog/pop-up).
Use applets, expect trouble. Use hidden applets, expect chaos..
I've been pondering over this problem most the afternoon and haven't yet found the most ideal solution so thought I would see what others think..
There is a legacy Win16 application that has to be modified (with the least effort) in order to communicate with a web based application.
The idea is such that in the Win16 app, the user will want to look up a specific code, so they'll click a button which will then launch the browser and allow them to navigate a specific set of pages until they find the result they desire, then they have the option of either pressing Select or Cancel.
Pressing Select should pass back a small string back to the app (around 10 characters) and close the browser. Cancel will likewise send a Cancel message back to the app and again close the browser window.
I can't see many choices available in implementation as the Win16 app is not able to call webservices, so I'm looking at using the clipboard, however that is not without problems.
I hope there's some other alternative I haven't thought of,
As always - all advice appreciated.
Thanks,
I'm developing an application using Vaadin framework. The application has a main menu, when user clicks a menu item, application executes descendant of AbstractMenuCommand class like
public class RunReportCommand extends AbstractMenuAction {
#Override
public void execute() throws MenuException {
Window = .... // create window here
openWindow(window);
}
protected void openWindow(Window window) {
application.getMainWindow().open(new ExternalResource(window.getURL()));
application.setMainWindow(window);
}
}
After this main browser window content is replace with needed window. After spending a lot of time I came to this solution: if you want replace browser window content with Vaadin Window you should always do
application.getMainWindow().open(new ExternalResource(window.getURL()));
application.setMainWindow(window);
Recently I got a new task to add a feature to application: users should have ability open windows in diffirent tabs and so the problem is that I have only one main window in vaadin (and window.open works only for the main window) but user can have a lot of diffirent windows in diffirent browser tabs, so if user clicks a menu item in browser tab that contains not main window, reloading vaading window content won't work.
Vaadin 7 & Vaadin 8
With versions 7 and 8 came the new concept and class of UI. You can now very easily open another window/tab in the user’s web browser. Fantastic new feature and great advantage for the Vaadin platform to support multi-window apps.
All the open windows/tabs share the same user session.
The tricky part is that for purposes of security and avoiding obnoxious behaviors, browsers do not allow JavaScript to directly open another window, known as "pop-up window". The new window/tab can only be opened as a direct result of a user gesture such as clicking a button.
So in Vaadin, you must use associate a BrowserWindowOpener object with a Button. You pass the .class of your UI subclass you wrote. That UI subclass is automatically instantiated for you, and displayed in the new window/tab.
All of this is explained well in the Handling Browser Windows page in the manual.
One limitation is that I see no direct way to pass objects to the new window/tab, that new UI-subclass instance. You might be able to do so indirectly. Perhaps posting an attribute in the session. Or perhaps setting string parameters on the URI of the new window/tab. I have asked about this issue of passing information to the new window for Vaadin 7 and asked again for Vaadin 8.
Vaadin 6
In 2011, I spoke with members of the Vaadin development team about the issue of multiple web browser windows or tabs for the same Vaadin 6 app. They strongly recommended against doing so. They said while it is possible, doing so requires much effort and tends to be troublesome and error-prone.
Instead they suggested using Vaadin TabSheet within a single browser window/tab.
The TabSheet is quite dynamic, so you can add and drop tabs as needed. Performance is surprisingly fast in my experience. Remember that only the content of the frontmost tab is actually in the user's browser window. The other tabs' content is in memory on the server, but is not a burden to the web browser/client. While tabs cannot be word wrapped and so tend to be wide, the TabSheet automatically provides scrolling through too many tabs to show.
Until release of Vaadin7, you can look at Navigator7 add-on (found here)
Navigator7 allows multi browser tabs navigaton. (A click in a browser tab, only affect this browser tab)
We use it in our application and it's work verry well.
Regards.
I noticed that if you're playing a song at http://listen.grooveshark.com/ and you hit the back button Flash is smart enough to keep on playing the music while navigating "back" inside the Flash application.
Is it possible to implement this sort of thing using Java Applets, or do Applets alway shut down when you navigate away from the page (even though the resulting page contains the same applet)?
Looks like grooveshark is being tricky with the URL fragment. They store the search after the # fragment delimiter in the URL, e.g. do a search for ween, and you get this URL
http://listen.grooveshark.com/#/search/songs/?query=ween
Then do a search for bungle and the URL changes to
http://listen.grooveshark.com/#/search/songs/?query=bungle
If you click the back button in your browser, the URL changes to the previous "ween" one, but the browser remains on the same page, because everything before the fragment identifier is the same. There's some javascript that's detecting the changed fragment and updating the UI accordingly.
You could probably do something like this with an applet, but it seems better suited to javascript. The good news is, your applet is going to be cached by the browser, so if you do switch to a different page the applet loading will happen quickly.
http://java.sun.com/docs/books/tutorial/deployment/applet/lifeCycle.html
When the user leaves the page, for
example, to go to another page, the
browser stops and destroys the applet.
The state of the applet is not
preserved. When the user returns to
the page, the browser intializes and
starts a new instance of the applet.
That being said, what you could do is save the state to the server when the applet is stopped and then restore the state from the server when it starts again. If you make it a signed applet it should be able to save the state locally.