Why doesn't Chrome show the selected <option> element after using the back button?

I have a <select> tag containing one <option> element:

 <select id="someselect"> <option value="2">B</option> </select> 

A single <option> later replaced with jQuery. The new parameter list always contains the old option:

 selected = $('#someselect').val(); $('#someselect').html('<option value="1">A</option><option value="2">B</option>').val(selected); 

This works as expected. However, when we go from a webpage to Google Chrome and click the back button, something strange happens. The select tag returns to its original state (it makes sense), but the only <option> element is not selected!

What is the reason for this behavior in Chrome?

I created a minimal working example: http://dl.dropbox.com/u/27566470/backdemo.html
Initially, there is only one <option> . First click "click" to replace the parameters (but keep the parameter "B"), then click "Google" to go from it, and then use the "Back" button in Chrome to see the <select> tag with only one that doesn't selected.

Edit: Clarify, I'm not interested in how to fix this. I'm curious why Chrome works this way. Serving the original (unmodified) DOM after using the "Back" button makes sense, but why is the only option chosen?

+6
source share
3 answers

To answer my own question, it seems to be a Chromium bug. I filed an error that is currently confirmed and triaged: http://code.google.com/p/chromium/issues/detail?id=125509
Therefore, I hope this should be fixed in the future :)

+4
source

Since when using the browser button, the version of the page cache is used, but your page has dynamic data that is lost, so the browser does not find the previously selected value. You can install it using jQuery:

 $(document).ready(function(){ $('#someselect').val('0'); }); 
+2
source

Since every browser that moves outside the document (# is still inside), when navigating through them, it loads the cached version of the server, and that Chrome changes the DOM when choosing an option that selects the selected attribute to the selected parameter, and when you return it again boot using selected

+2
source

Source: https://habr.com/ru/post/914229/


All Articles