Solved

Firefox onbeforeunload problem

Posted on 2009-04-08
5
2,819 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Several part series to implement Internet Explorer 11 Enterprise Mode
This article discusses how to create an extensible mechanism for linked drop downs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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.

786 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