Suppose the user closes the window without Logging out, in firefox and in Safari (Mac OS) , the user will be automatically logged in,when they open a new window or a new tab.
Some additional thought maybe required for this. The condition described should not be a problem.
First off you may not want to log users out just because they open a link on your page in a new tab. With tabbed browsers now being so common this probably happens often and would cause a lot of confusion for your users if they where logged out each time they selected "Open in a new tab"
Also if the user completely closes their browser then and then reopens it a new session ID should be getting generated for them. This is not entirely true with some new auto session recovering features. If they do still have the same session ID, and that is still valid (i.e. not timed out) then there should not be a problem.
If there session has timed out they should be getting forwarded to a login page.
Is there any way to identify the event of closing the window or tab, opening a new window or tab using javascript, evenif its opened using mouse or keyboard?
You could trigger a request to the server to log the user out on the onunload event for the body tag. This is not really that reliable though.