A simple JavaScript / HTML issue. (Or so I thought)
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Plusnet Community
- :
- Forum
- :
- Other forums
- :
- Tech Help - Software/Hardware etc
- :
- A simple JavaScript / HTML issue. (Or so I thought...

A simple JavaScript / HTML issue. (Or so I thought)
12-09-2019 12:57 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
I'm having an issue with this code from my JS file:
window.onbeforeunload = function() { console.log("Logging out") ; location.replace("http://secure.local.lan/logout.html") ; console.log("Logged out") ; };
In that the page doesn't appear to be loaded. I need to force the user to load the logout.html page before they leave this secure vHost so Apache can free their login so they can log in again.
I can't help but think I am missing something here, as I see both the messages appear on the console, and the browser navigates to the link chosen (i.e. Home), but I know logout.html isn't called. Your thoughts would be appreciated.
If you need to know more, please ask.
Re: A simple JavaScript / HTML issue. (Or so I thought)
12-09-2019 1:02 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
If it helped click the thumb
If it fixed it click 'This fixed my problem'

Re: A simple JavaScript / HTML issue. (Or so I thought)
12-09-2019 1:11 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
I have already tried that @dvorak and it 'failed' in the same way so I tried this version of it.

Re: A simple JavaScript / HTML issue. (Or so I thought)
12-09-2019 2:28 PM - edited 12-09-2019 2:29 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
OK, after a bit of reading I have a fix using this and it's a more elegant solution all round (I think).
window.addEventListener('beforeunload', (event) => {
// Dump all of the session cookies document.cookie.split(";").forEach( (c) => { document.cookie = c.replace(/^ +/, "").replace(/=.*/, "=;expires=" + new Date().toUTCString() + ";path=/"); });
// Send a beacon notice to the logout page navigator.sendBeacon("http://secure.local.lan/logout.html", null) ; });
Re: A simple JavaScript / HTML issue. (Or so I thought)
12-09-2019 2:54 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
If it helped click the thumb
If it fixed it click 'This fixed my problem'
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Plusnet Community
- :
- Forum
- :
- Other forums
- :
- Tech Help - Software/Hardware etc
- :
- A simple JavaScript / HTML issue. (Or so I thought...