I am creating a file sharing web application. When a user edits an existing file -- by clicking the edit link for the file on the "directory view" page (which displays a list of all files in that "directory) -- the file's checkout value is changed from '0' to '1' to indicate that it has been checked out. This means that other users that visit the "directory view" page will not be given the option to edit that file.

Here's the problem. If the user editing the file finishes editing by clicking the "submit" button (or clicks the "return to directory view" button), the flag will be reset so that the file is checked back in (and available for others to edit). But if instead the user (a) clicks the browser's back button or (b) closes the browser window entirely, the file never get's checked back in.

For situation (a), is there a way to "intercept" the browser back command so that the file is checked back in? I.e., when the user clicks the back button, the page runs the "check the file back in" php script before returning the user to the directory view page.

For situation (b), is there a generally accepted method for such situations? For instance, I might place a time limit on checked out files so that after a file is checked out, it is automatically checked back in after 30 minutes or so?

Thanks.

    I would take a look at window.unload() javascript function although It may not work fully in Opera and Safari. Javascript is not my expertise so I would suggest researching further 🙂

    This should be able to handle closing the window as well as back and forward submissions.

    Not sure I would want to set a timer on the file editing unless your guaranteed that your users will only edit during session. I would in the least provide an admin interface for forcing the unlocking of a file. Can also associate a session to a locked file so you can tell if it has been inactive for a certain period of time.

      I did consider using:

      window.onbeforeunload = function() {
      	return 'Please use the \'Return\' button';
      }

      but it catches any attempt to leave the page (i.e., clicking the submit button). I really need something that will only intercept attempts to leave the page by hitting the browser's back button.

      Any ideas? Sorry, my PHP is pretty good but my grasp of Javascript is very basic.

        Try asking in a Javascript forum. There would be a higher ratio of Javascript experts/nonexperts there.

          Write a Reply...