Angular 6 - logout user when only browser close not on refresh Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Detect browser or tab closingStop setInterval call in JavaScriptWhere can I find documentation on formatting a date in JavaScript?Detect when browser receives file downloadevent.preventDefault() vs. return falseHow to close current tab in a browser window?How to decide when to use Node.js?What's the difference between event.stopPropagation and event.preventDefault?How to delete a localStorage item when the browser window/tab is closed?how to logout a user when browser closedAngular 6 - logout when only browser close not on refresh
Can anything be seen from the center of the Boötes void? How dark would it be?
Is CEO the profession with the most psychopaths?
If my PI received research grants from a company to be able to pay my postdoc salary, did I have a potential conflict interest too?
Why didn't Eitri join the fight?
How to compare two different files line by line in unix?
Is grep documentation wrong?
Is it common practice to audition new musicians one-on-one before rehearsing with the entire band?
What is the meaning of the simile “quick as silk”?
Chinese Seal on silk painting - what does it mean?
How do I make this wiring inside cabinet safer? (Pic)
Do I really need to have a message in a novel to appeal to readers?
Why are both D and D# fitting into my E minor key?
Delete nth line from bottom
First console to have temporary backward compatibility
Around usage results
Extracting terms with certain heads in a function
Using audio cues to encourage good posture
How to convince students of the implication truth values?
Does classifying an integer as a discrete log require it be part of a multiplicative group?
How come Sam didn't become Lord of Horn Hill?
Fantasy story; one type of magic grows in power with use, but the more powerful they are, they more they are drawn to travel to their source
Do I really need recursive chmod to restrict access to a folder?
8 Prisoners wearing hats
Crossing US/Canada Border for less than 24 hours
Angular 6 - logout user when only browser close not on refresh
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!Detect browser or tab closingStop setInterval call in JavaScriptWhere can I find documentation on formatting a date in JavaScript?Detect when browser receives file downloadevent.preventDefault() vs. return falseHow to close current tab in a browser window?How to decide when to use Node.js?What's the difference between event.stopPropagation and event.preventDefault?How to delete a localStorage item when the browser window/tab is closed?how to logout a user when browser closedAngular 6 - logout when only browser close not on refresh
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
logout the user when he close the browser not on refresh
@HostListener('window:beforeunload', [ '$event' ])
unloadHandler(event)
this.logout()
logout()
localStorage.removeItem('id');
this.router.navigate(["/login"]);
I use this, it works but the user also logout on refresh the browser
javascript angular
add a comment |
logout the user when he close the browser not on refresh
@HostListener('window:beforeunload', [ '$event' ])
unloadHandler(event)
this.logout()
logout()
localStorage.removeItem('id');
this.router.navigate(["/login"]);
I use this, it works but the user also logout on refresh the browser
javascript angular
where you stored your user login details.
– Sachin from Pune
Mar 22 at 9:52
localstroage @SachinfromPune
– Balaji
Mar 22 at 9:55
Please always provide a Minimal, Complete, and Verifiable example
– Pitto
Mar 22 at 9:57
add a comment |
logout the user when he close the browser not on refresh
@HostListener('window:beforeunload', [ '$event' ])
unloadHandler(event)
this.logout()
logout()
localStorage.removeItem('id');
this.router.navigate(["/login"]);
I use this, it works but the user also logout on refresh the browser
javascript angular
logout the user when he close the browser not on refresh
@HostListener('window:beforeunload', [ '$event' ])
unloadHandler(event)
this.logout()
logout()
localStorage.removeItem('id');
this.router.navigate(["/login"]);
I use this, it works but the user also logout on refresh the browser
javascript angular
javascript angular
edited Mar 22 at 10:00
Balaji
asked Mar 22 at 9:43
BalajiBalaji
13
13
where you stored your user login details.
– Sachin from Pune
Mar 22 at 9:52
localstroage @SachinfromPune
– Balaji
Mar 22 at 9:55
Please always provide a Minimal, Complete, and Verifiable example
– Pitto
Mar 22 at 9:57
add a comment |
where you stored your user login details.
– Sachin from Pune
Mar 22 at 9:52
localstroage @SachinfromPune
– Balaji
Mar 22 at 9:55
Please always provide a Minimal, Complete, and Verifiable example
– Pitto
Mar 22 at 9:57
where you stored your user login details.
– Sachin from Pune
Mar 22 at 9:52
where you stored your user login details.
– Sachin from Pune
Mar 22 at 9:52
localstroage @SachinfromPune
– Balaji
Mar 22 at 9:55
localstroage @SachinfromPune
– Balaji
Mar 22 at 9:55
Please always provide a Minimal, Complete, and Verifiable example
– Pitto
Mar 22 at 9:57
Please always provide a Minimal, Complete, and Verifiable example
– Pitto
Mar 22 at 9:57
add a comment |
1 Answer
1
active
oldest
votes
In your app.component.ts
Add before your constructor(),
@HostListener('window:beforeunload')
unloadHandler(event)
localStorage.removeItem('currentUser');
If I use this it is also working on page refresh, I need this function to work only when the user close the browser or tab
– Balaji
Mar 22 at 10:03
please go through this link stackoverflow.com/questions/3888902/…
– Sachin from Pune
Mar 22 at 11:42
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55296814%2fangular-6-logout-user-when-only-browser-close-not-on-refresh%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
In your app.component.ts
Add before your constructor(),
@HostListener('window:beforeunload')
unloadHandler(event)
localStorage.removeItem('currentUser');
If I use this it is also working on page refresh, I need this function to work only when the user close the browser or tab
– Balaji
Mar 22 at 10:03
please go through this link stackoverflow.com/questions/3888902/…
– Sachin from Pune
Mar 22 at 11:42
add a comment |
In your app.component.ts
Add before your constructor(),
@HostListener('window:beforeunload')
unloadHandler(event)
localStorage.removeItem('currentUser');
If I use this it is also working on page refresh, I need this function to work only when the user close the browser or tab
– Balaji
Mar 22 at 10:03
please go through this link stackoverflow.com/questions/3888902/…
– Sachin from Pune
Mar 22 at 11:42
add a comment |
In your app.component.ts
Add before your constructor(),
@HostListener('window:beforeunload')
unloadHandler(event)
localStorage.removeItem('currentUser');
In your app.component.ts
Add before your constructor(),
@HostListener('window:beforeunload')
unloadHandler(event)
localStorage.removeItem('currentUser');
answered Mar 22 at 10:02
Sachin from PuneSachin from Pune
250313
250313
If I use this it is also working on page refresh, I need this function to work only when the user close the browser or tab
– Balaji
Mar 22 at 10:03
please go through this link stackoverflow.com/questions/3888902/…
– Sachin from Pune
Mar 22 at 11:42
add a comment |
If I use this it is also working on page refresh, I need this function to work only when the user close the browser or tab
– Balaji
Mar 22 at 10:03
please go through this link stackoverflow.com/questions/3888902/…
– Sachin from Pune
Mar 22 at 11:42
If I use this it is also working on page refresh, I need this function to work only when the user close the browser or tab
– Balaji
Mar 22 at 10:03
If I use this it is also working on page refresh, I need this function to work only when the user close the browser or tab
– Balaji
Mar 22 at 10:03
please go through this link stackoverflow.com/questions/3888902/…
– Sachin from Pune
Mar 22 at 11:42
please go through this link stackoverflow.com/questions/3888902/…
– Sachin from Pune
Mar 22 at 11:42
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55296814%2fangular-6-logout-user-when-only-browser-close-not-on-refresh%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
where you stored your user login details.
– Sachin from Pune
Mar 22 at 9:52
localstroage @SachinfromPune
– Balaji
Mar 22 at 9:55
Please always provide a Minimal, Complete, and Verifiable example
– Pitto
Mar 22 at 9:57