Function when the browser window is closed



  • I'm trying to make an account of the visitors to the site, I saw it on a lot of resources, but something didn't come out.

    There's a base where the number of visitors is stored, there's a php scrip that should be added to the base +1 at the entrance of the camper. readyand -1 when it comes from the site (with this problem). There's a function that sends ajax-request for this php scrupt, and there's an event. onbeforeunload or unloada function.

    I don't know who's the culprit on this list, but the function's gonna make a difference when it closes the page at its next download. I mean, the function only works in updating the page or rebuilding it (cntrl+shift+TEven before the event readybut if the page is closed, there's no effect at all. Testing only firefoxthat browser is a priority.

    Code itself:

    HTML:

    <script>window.onunload = putout();</script>
    

    JS:

    function putout() {
        $.ajax({
            type: "POST",
            url: "./php/process.php",
            data: {
                'function': 'putout',
                'def': def,
            },
            dataType: "json",
            success: function(data) {
    
        },
    });
    

    }

    PHP:

    include ('./php/connect.php');
    mysql_query("UPDATE numb SET numb=numb-1");

    I also heard that the opera is ignoring these events at all, but how can it be a cross-star to implement the website visitor?

    P.S. The text has already been re-examined, it's not my style of presentation, take note. Actually, I hate being able to get away with my publications to people, and that's annoying.



  • The method is performed when the page is downloaded, but it does not work when unloaded due to incorrect use.

    This code.

    window.onbeforeunload = putout();
    

    performance immediately after loading Scripta, before the page is ready. At the same time, no hendler will join the event because the function will return undefined.

    In order to indicate the hendler for the event, we need to remove the method:

    window.onbeforeunload = putout;
    

    The function will not be called at the start, but will be called before discharge.

    Anyway, This is an incorrect approach to user counting.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2