disable viewing past content/history in html

By : Daniel
Source: Stackoverflow.com
Question!

I've got an html from on a public access tablet. Is there a way to reliably prevent a user from going back in history to view past form submissions?

I'm looking to solve it either server-side or using javascript, or combination of the two.

I tried javascript code that prevent the back action, but it only works on the immediate back, press and hold to view further back options still allows going back.

The form is set to remember values when submission fails, but should not be able to get them after a successful submit.

is this perhaps better to do using sessions and handle using php?

By : Daniel


Answers

There are many ways to prevent re-submission of forms through clicking the back button:

One way is to set all the form fields to be empty, this can be done on load of the page.

You could use sessions to ensure that the user has already submitted the form. Cookies and/or local storage can be used as well.

However, querying the database to check for duplicates or resubmissions, or setting the form fields to empty strings on the client side would be a better option, as a user could delete cookies and clear local storage.



Here is the general idea how to use EventWaitHandles. You need to Reset it before doing the work, and Set it when you are done.

In the example below I have made the ResetEvent property static, but I suggest you pass the instance somehow instead, I just could not do it without more details about your architecture.

class Login
{
     private Thread performThread;
     public static ManualResetEvent ResetEvent { get; set; }
     public bool Login(Userinfo)
     {
        // do tasks like authenticate
        if(authenticationValid)
        {
            PerformLoginAsyncThread(UserInfo);
            //continue to homepage
        }
    }   

    private void PerformLoginAsyncThread(UserInfo)
    {
        ResetEvent.Reset();
        performThread = new Thread(() => 
        {
            //do stuff
            ResetEvent.Set();
        });
        performThread.Start();
    }
}

class HomePage
{
    public void OnClickFindProduct
    {
        bool finishedPostLoginThread = Login.ResetEvent.WaitOne(8000);
        if(finishedPostLoginThread)
        {
            // proceed to Find Product page
        }
        else
        {
            //If taking more than 8 seconds, throw message and exit app
        }
    }
}
By : slawekwin


I don't have the privalage to comment but you can use the required field as follows

 <input type="radio" name="question-1-answers" id="question-1-answers-A" value="A" required=true />

using this way the user will have to click all the required fields before submitting a form.



This video can help you solving your question :)
By: admin