Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Firefox onbeforeunload problem

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

839 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