Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8060577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:02:23+00:00 2026-06-05T10:02:23+00:00

I’m entering my second day of web development, so be gentle! I’m trying to

  • 0

I’m entering my second day of web development, so be gentle!

I’m trying to code a little web app which allows a user to visit a site and click/tap the screen to direct a dot on another screen. To do this I’ve set up a Django server to handle the data, I’m using Javascript to get the click/tap position, send that via POST data to the server, then draw it using Processing.js (my boss is big on Processing, and this is really a test for interactivity with Processing on a big screen via cellphones, etc).

I’m not a web developer so even this simple task has been quite the challenge. I was feeling quite comfortable up until this point. When a user loads the interaction web page, they are assigned an arbitrary user id for the app which lets them control their specific dot. I want that dot to be deleted when the user leaves the page. I plan on implementing a backup timeout later, but I’d like to have the instant delete first for the best experience, closest to expectations. (Our end goal I think is to have a nice big screen running a simple game, where people can walk by, use the QR code on the screen to launch the interaction site, and join the game. When they get bored they just close the site and that deletes them from the game screen, simple).

In my interaction page I have this code (apologies for poor variable names):

<body onload="load()" onbeforeunload="unload()"> 
<canvas id="canv" width="1000" height="1000"/>

<script type="text/jscript">
    var userid;
    
    function load() {       
        userid = Math.floor(Math.random()*1000) //this will of course be changed
        var canv = document.getElementById('canv');
        canv.addEventListener('click', onCanvasClick);
        //$(window).unload(unload());
    }
    
    function onCanvasClick(event) {
        var cx, cy;
        var canvv = document.getElementById('canv');
        
        canoffset = $(canvv).offset();
        cx = event.clientX + document.body.scrollLeft + document.documentElement.scrollLeft - Math.floor(canoffset.left);
        cy = event.clientY + document.body.scrollTop + document.documentElement.scrollTop - Math.floor(canoffset.top) + 1;
        
        cx = (((cx - 500) / 500) * 3);
        cy = (((cy - 500) / 500) * 3);
        
        var data = {
            x: cx,
            y: cy,
            id : userid,
            deleteMe : 0
        };
        $.post("", data);
    }
    
    function unload() {
    //send remove code for this user
        var data = {
            x: 0,
            y: 0,
            id: userid,
            deleteMe : 1
        };
        $.post("", data);
        //alert("test");
    }
</script>

This POST data is supposed to be sent to the Django server. The POST sent from the onCanvasClick function is successfully received, and I see the dots moving according to plan. However, the POST sent from the unload() function is not received, no matter if I use the beforeunload or unload event (or, as you can see commented out, the JQuery unload). However, the commented-out alert still fires.

What am I missing here? Is there a tried-and-true way to tell the server that a user has left the page?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T10:02:25+00:00Added an answer on June 5, 2026 at 10:02 am

    There is no 100% dependable way to tell when someone has left your page. The best you can do is use some AJAX polling and assume that the user has left once the polling stops or perhaps use web sockets (not universally available) to keep a connection open.

    For example – I’m browsing your site with my tablet, and I lose my Internet connection. beforeunload will not help you in that situation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to select an H1 element which is the second-child in its group
I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am writing an app for my school newspaper, which is run completely online
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I used javascript for loading a picture on my website depending on which small
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm interested in microtypography issues on the web. I want a tool to fix:
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.