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... :)

 

Link to comment
Share on other sites

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?

 

 

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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.

 

 

 

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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');

}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.