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;








0















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










share|improve this question
























  • 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

















0















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










share|improve this question
























  • 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













0












0








0


0






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










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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

















  • 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












1 Answer
1






active

oldest

votes


















0














In your app.component.ts



Add before your constructor(),



@HostListener('window:beforeunload')
unloadHandler(event)
localStorage.removeItem('currentUser');






share|improve this answer























  • 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











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
);



);













draft saved

draft discarded


















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









0














In your app.component.ts



Add before your constructor(),



@HostListener('window:beforeunload')
unloadHandler(event)
localStorage.removeItem('currentUser');






share|improve this answer























  • 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















0














In your app.component.ts



Add before your constructor(),



@HostListener('window:beforeunload')
unloadHandler(event)
localStorage.removeItem('currentUser');






share|improve this answer























  • 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













0












0








0







In your app.component.ts



Add before your constructor(),



@HostListener('window:beforeunload')
unloadHandler(event)
localStorage.removeItem('currentUser');






share|improve this answer













In your app.component.ts



Add before your constructor(),



@HostListener('window:beforeunload')
unloadHandler(event)
localStorage.removeItem('currentUser');







share|improve this answer












share|improve this answer



share|improve this answer










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

















  • 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



















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript