Chrome does not cache hidden form field values โ€‹โ€‹for use in browser history

I have an ASP.Net web form that contains both text field fields and hidden fields. Hidden field values โ€‹โ€‹are dynamically changed using client-side JavaScript. Publishing a form, checking values, and redirecting to another page works as expected.

However, when I use the back-to-back button to display the previous page, I expect that so that all form fields are still filled with the values โ€‹โ€‹that were published.

In IE and Firefox, this applies to both text and hidden input fields.

In Chrome, this is ONLY for text fields. The value of hidden fields is lost.

Is it true that when navigating in browser history, Chrome never updates the dynamic values โ€‹โ€‹of dynamically set hidden forms?

I put a small sample together to demonstrate the problem, and can provide, if necessary. I wanted to ask a question first to find out if this behavior is good and what I should accept.

+13
google-chrome browser-history back-button
Oct 26 2018-10-26
source share
3 answers

You should not rely on this behavior. It differs from browsers, even among browser versions. This behavior is not described in any standards. If you want your fields to have specific values, you can use cookies or always make requests to the server when the page loads, or use more modern methods such as local storage (it is not widely supported).

+4
Oct 26 2018-10-26
source share

This problem can be solved with a little trick.

Problem: form fields with type = hidden with dynamically set values โ€‹โ€‹are not processed by the Chrome browser.

So, the solution is to change the type of the field to text and use some other method to hide the visible text fields. This can be achieved by surrounding all text fields that carry values โ€‹โ€‹that should be hidden using a pair of DEV tags and assigning the style as a display: none

Then on the page you will not see text fields containing hidden values, and it will work correctly with the JavaScript browser.

before

<input type=hidden name=item_no value=00001> 

after

 <div style="display: none"> <input type=text name=item_no value=00001> </div> 
+14
Jun 17 '11 at 10:10
source share

I canโ€™t comment, maybe my representative is too low, but I thought it was important to mention this.

I just ran into this problem in Opera , so I borrowed the Sanesh Fernando solution that worked around hidden fields that are not being restored (thanks Sanesh). However, the reason for me was that Javascript fires before the form fields are updated, so if you check the values โ€‹โ€‹with javascript as I did, I had to add setTimeout to ensure Opera is updated before I check the values.

Cookies, as indicated otherwise, but what about the ridiculous EU directive that requiring a user to use cookies is not a solution for me.

0
Feb 12 2018-12-12T00:
source share



All Articles