1

i have this strange issue with IE9 (didn't test it in any other IE) - when i logged on to the website and whenever i refresh the page the following code fires:

jQuery(window).bind("beforeunload", function() {
    $.get('session_destroy.php', function() {
    //  alert('done');
    });
});

funny bit is that when i call developer tools F12 - and refresh then, i can see a quick call to session_destroy.php - but it doesn't log me out on refresh!

here is my document definitions:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> //- note this i need because on intranet sites IE gt 8 force compatibility mode of IE7 - this makes all jquery sucks..
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

don't know whether this is related, but sometimes i have to loggin twice, as it doesn't do it from the first time... i also use ajax to log in:

$(document).ready(function(){

    $("#submit").click(function(){
        username = $("#username").val();
        password = $("#password").val();
        $.ajax({
            type: "POST",
            url: "login_db.php",
            data: "username="+username+"&password="+password,
            success: function(html){
                if(html.length>0)
                {
                    switch(html)
                    {
                        case "1": tab = "Production";
                        break;
                        case "2": tab = "Recordings";
                        break;
                        default: tab = "Summary";
                    }
                    window.location.hash = '';
                    var url=window.location;

                    window.location.href= url+tab;
                    location.reload();
                }
                else
                {
                    $("#add_err").html("Wrong username or password");
                }
            }
        });
        return false;
    });
});

everything works fine in Firefox and Chrome

Elen
  • 2,345
  • 3
  • 24
  • 47
  • A session will be destroyed when closing the browser. Why you want this by javascript? – Ron van der Heijden Sep 20 '12 at 12:00
  • it's not my question and no it doesnt get destroyed on browser close just like that. that's why i had to have it – Elen Sep 20 '12 at 14:05
  • Lies, Sessions will get destroyed on browser close! I think you have to learn more about [Sessions](http://www.tizag.com/phpT/phpsessions.php) – Ron van der Heijden Sep 20 '12 at 14:25
  • @Bondye - Yes i have! but chrome like to get back on the last data captured! so despite session destroyed it will still open like user is still logged on. and all the amendments that user does during his "fake" session cant be saved. so chrome must be told that session IS destroyed. – Elen Sep 20 '12 at 14:44
  • Allright, now on-topic. 1. An submit button.click() dont work properly. Use the [submit()](http://api.jquery.com/submit/) function. 2. I see u dont use the ajax well. consider using `done(function() { alert("success"); })`, `.fail(function() { alert("error"); })` Explained [here](http://api.jquery.com/jQuery.ajax/) 3. use better DOCTYPE ` ` – Ron van der Heijden Sep 20 '12 at 14:47
  • @Bondye - 2. i don't use feed back on ajax because i dont need it not because i cant. 1. it's not submit that is the problem. 3. - what do u mean? – Elen Sep 20 '12 at 15:02
  • How is #submit not a button in a form? How is username and password posting not submit? Please show us more HTML. – Ron van der Heijden Sep 21 '12 at 06:30
  • @Bondye it is not log in that is the problem. my question is about beforeunload firing in IE9 on F5.... – Elen Sep 21 '12 at 08:57
  • Like told [here](http://stackoverflow.com/questions/9985712/preventing-onbeforeunload-dialogs-in-ie9) `You cannot send an AJAX request while the page is unloading as most browsers block it. You should ask the user to stay on the page if there is dirty data. That's all you should do from your onbeforeunload handler. Try your code without calling $.post and it should behave as expected` – Ron van der Heijden Sep 21 '12 at 10:32
  • @Bondye i see!... thanks for the tip... i'll look into other ways – Elen Sep 21 '12 at 10:39

0 Answers0