Jump to content

Change variable/Database value if browser is closed??


New Coder

Recommended Posts

Hi all,

 

I was wondering if it was possible to change a value within a DB if a user closes their browser via the bowsers close crosses or menu-file-exit?

 

example:

I have a DB table with users details and a column called edit which is defaulted to "N".

A "Master user" selects an individual or a group of "standard users" from a list which then sets the standard users edit field to "Y". This will then allow these standard users to access other parts of the site, edit profiles etc.

Now, I can obviously create a button on a page that will reset "Y's" to "N's" removing editting rights. But if the "Master user" forgets to use the reset edit button, closes browser and goes home they will leave people with editing rights etc.

 

Is there a way round this?

 

Many Thanks

 

p.s i hope my example makes sense... :)

 

I would use a cron job that ran every once in a while.

 

It would open a php file, and connect to the database and change the proper Y's to N's

 

This file would have to be placed outside the root directory of your web site so it can not be accessed from the web a.k.a. a browser.

PHP is not like Visual Basic where you can do something like on a close event.  It's a server side script that delivers a page.  Maybe JS can do it, but PHP can't.

 

Hi all,

 

I was wondering if it was possible to change a value within a DB if a user closes their browser via the bowsers close crosses or menu-file-exit?

 

 

I just tried this, and at least I'm getting the alert message. Try making an Ajax call instead of the alert and let me know ;)

<html>
<head>
<script type="text/javascript" language="javascript">
function triger_acction(){
alert('Browser is being closed!');
}
</script>
</head>
<body onunload="triger_acction()">
Hello!
</body>

Thanks people,

 

Working with your example jorgep I have managed to stop them from closing the window (in a round about way) by forcing it to open a new window.

 

<html>

<head>

<Script Language="JavaScript">

function triger_action() {

var load = window.open('http://www.website.com');

}

</script>

</head>

<body onunload="triger_action()">

Hello!

</body>

 

So I could make it open a page that says you have not removed editing rights click he to remove and so on.

 

 

 

With a combination of things I now have:

<html>
<head>
<Script Language="JavaScript">
function triger_action() 
{
var where_to= confirm("Have you removed editing");
if (where_to== true)
{
     window.close();
}
else
{
var load = window.open('http//:www.website.com');
  }
}
</script>
</head>
<body onunload="triger_action()">
Hello!
</body>

 

Which kinda works.

It would be a wierd situation if you sent them to another site with this code as they would never be able to close browser...

Yeah, thats weird hehehe, I've never tried that, that would be sooo annoying!

Good thing it worked ;)

I would have tried an ajax approach, instead of doing this:

if (where_to== true){

    window.close();

} else {

    var load = window.open('http//:www.website.com');

}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.