Solved

Firefox onbeforeunload problem

Posted on 2009-04-08
5
2,815 Views
Last Modified: 2013-12-07
Hi there,

I want logout users on browser window on close.

How can I do this?

I did try 'onbeforeunload' and 'onunload', but doesn't work.

(logout.php - only update an db-table)

This code working on IE. But no FF

(I'm so sorry for my bad english)

My javascript code:
<script type="text/javascript">

window.onbeforeunload = function() {

	var myRequest = new Request( { method: 'get', url: 'logout.php' } ).send();

}

</script>

Open in new window

0
Comment
Question by:bahadirkocaoglu
  • 2
  • 2
5 Comments
 
LVL 15

Expert Comment

by:fsze88
ID: 24104184
I tested
<script type="text/javascript">
window.onbeforeunload = function() {
        alert('abc');
}
</script>

on ff3 It works
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24104291
Yes, because it does not depend on other scripts on that page.
0
 
LVL 2

Author Comment

by:bahadirkocaoglu
ID: 24110664
But it's working all pages. I want only window close, not on navigation.
0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 125 total points
ID: 24114654
This is an extremely frequently asked question
your application should NOT need to have the user log out on close and the browsers are notoriously not telling you when they close

IE can be detected with some silly event location script and FF cannot as far as I know.

Fix your application instead of relying on being told that the browser closed

That said, have a look here if any work for you. If they do let us know too.

http://www.google.com/search?q=php+detect+browser+close
0
 
LVL 2

Author Closing Comment

by:bahadirkocaoglu
ID: 31568094
Thank you!
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This Micro Tutorial will demonstrate how to add subdomains to your content reports. This can be very importing in having a site with multiple subdomains.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now