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

How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?