Click here to Skip to main content
15,920,383 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
How to create game rooms that only one player can be in?
I know, I Can set Applications which stores if a player is in it or not.
But the problem comes when he closes the browser with [x], then I need to change the application value.
I thought to set a timer for 2 minutes and if the user does not refresh the page in this time then I know the Application should change value. there is a way to keep the timer running after he closed the browser?
I tried also with database Table and when a javascript happens it goes to a webmethod which changes the table values.

Some things that might help,
How to create a JavaScript function which happend ONLY when the browser is closed?
How to create the rooms in other way.

Here is the javascript I have

C#
function DetectBrowserExit()
{
    alert('Execute task which do you want before exit');
    PageMethods.AppOff();


}

    window.onbeforeunload = function () { DetectBrowserExit(); }


AppOff changes the table values,
but the script runs even if a user refreshed the page.

Any Ideas?
Thank you.
Posted
Comments
[no name] 7-Jun-11 19:12pm    
You have been asking this same question, or questions related to it, for some time now. Isn't it time to accept the task is beyond you? Try something less challenging until your skills improve.
Member 7966831 7-Jun-11 19:42pm    
I am not doing it for my fun but There might be a chance I solved it with a code I found.

1 solution

Here it is I think it happens on close only:

XML
<head>
<script type="text/javascript">

    var myclose = false;

    function ConfirmClose() {
        if (event.clientY < 0) {
            event.returnValue = 'Any message you want';

            setTimeout('myclose=false', 100);
            myclose = true;
        }
    }

    function HandleOnClose() {
        if (myclose == true) PageMethods.AppOff();
    }
</script>
</head>


<body onbeforeunload="ConfirmClose()" onunload="HandleOnClose()">
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900