How to disable browser backbutton after signout from website in java [duplicate] - javascript

This question already has answers here:
Prevent user from seeing previously visited secured page after logout
(7 answers)
Closed 6 years ago.
How to disable the browser backbutton after signout / logout for my website. I am using jsp and struts1, i am using this code but this is not working properly (i.e in all pages the browser backbutton is not working but my requirement is was not that one) .
<script>
history.forward();
</script>
Please any one help me.

You don't need to disable the browser back button. You need to expire/invalidate the session when the user clicks logout. Then even if he clicks the back button, your app should detect that this request now comes with an invalid session, and so it would forward him to the login page (as he has no valid session already).

Related

How to find the tab and refresh it in browser by name [duplicate]

This question already has answers here:
Communication between tabs or windows
(9 answers)
Closed 5 years ago.
I have 2 open tabs from same application and same domain: tab1 and tab2, they are not opened from each other I mean I can not use win.open(....) and win.reload() So is there any way to find the tab by name and refresh it. The objective is from tab1 find the tab2 and refresh it automatically. any idea?
I see 2 solutions to your problem:
check if your document focus has changed. You only need to refresh it when tab gets visible again.
register open tabs in a session array and flag them with ajax calls or with server side code if they need to refresh. each page (tab) can check it's flag, refresh itself if needed and clear flag. I will need to know what might trigger the need to refresh for a better approach.

Ionic framework without Hash or History [duplicate]

This question already has answers here:
Clicking the device back button closes the app instead of going back to previous page
(5 answers)
Closed 7 years ago.
I'm using Ionicframework for my first android application my problem is my application has many tabs and inner pages and user can go through them but when user try to close application the back history pages are repeated on mobile back Navigation button(not the one in the UI header) just like normal browser of android or chrome.
What I want when it's on main page and user press Mobile Back button he should be out of application and don't go through all the tabs which he has viewed previously, as it make sense.
I've tried this but nothing works.
$ionicHistory.clearHistory();
$ionicHistory.nextViewOptions({
disableAnimate: true,
disableBack: true
});
Thank you
$ionicPlatform.registerBackButtonAction(function (e) {
e.stopPropagation();
e.preventDefault();
$window.navigator.app.exitApp();
,101);
The code above registers a back-button action with priority 101 and closes the app on back-button if there's no modal / popup / side menu open. You might want to check something like if ($state.current.name !== YOUR_HOME_STATE_NAME) {.
See also: Documentation of $ionicPlatform
EDIT:
Since you still want to navigate backwards, you can use the $ionicHistory-Service with it's goBack()method.

detect closing current tab on browser and call ajax function [duplicate]

This question already has answers here:
JavaScript, browsers, window close - send an AJAX request or run a script on window closing
(9 answers)
Closed 6 years ago.
I am working on a website, where at a time one admin can login. I implemented this by saving value in database. Now the problem is when current admin forget to logout, the value in database do not change and another admin can't login again. Even this current admin can't login later on, cause the value in database is checked in condition.
I have looked in window.onbeforeload and window.onunload functions, but it only trigger on page refresh etc, not detecting browser close tab/window. I want to detect closing browser tab and call function upon close, so I can change value in database using ajax.
Any help will be appreciated! Thanks
The event you are looking for is onbeforeunload
Use window.uneforeunload which is trigged when tab/window is closed.
Updated
window.onbeforeunload = function (){
// update your database from here before page closed
}
DEMO

logout when the browser close, onunload javascript [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How we call logout servlet on browser close event
I want my site to automatically logout user when the browser closes. I use onunload in javascript. Now, my problem is it always logout the user everytime the user navigates to other page. What I want is just to logout when the browser closes.
Here's my code:
<script type="text/javascript">
window.onbeforeunload = confirmExit;
window.onunload = logout;
function confirmExit() {
return "Are you sure you want to leave?";
}
function logout() {
window.location = '<?php echo WEBSITE_URL ?>?logout=true';
}
</script>
Hope someone will help me ASAP!
In your case its better to send a ajax request to do the task rather then redirecting the user to logout.
Also send it on onbeforeunload
Or a better idea will be add a cookie with user last activity. and check on every page load the if the last activity is more then the required limit server redirect to the login page clearing the session.
I don't think it's possible to detect in javascript when the window is closed. As you've found out onunload event doesn't have the information why the page is unloaded: if the user closes the window or navigates to a different page.
What is more, the user may navigate to a different page by typing the url in the address bar - you might want to 'log him out' in that case too.
The best way to achieve it is to have a timeout on your session. This will work event if the browser crashes.

How to alert user to not close the window while he has submitted the form to process? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Javascript To Get An Alert When Closing The Browser Window
I am having a site on which users are visiting and uploading video, in that i am having a problem that users are closing the browsers or navigating from the page without letting the upload process to complete, i want to show a alert box to the user to not close the window or not to navigate from the page when uploading process is going on, i tried it through window.unload but it will not work for me because as the uploading process is going on the page will be submitted so that event will always be called, please tell me the way to show the alert box to users on window close or they navigate from the page.
Thanks in advance,
Ravinder Singh
Did you try to use:
window.onbeforeunload

Categories