This works as expected on Firefox but not on Chrome.
Fiddle example: http://jsfiddle.net/8Ab6c/1/
setTimeout(function(){
$('#s1').append("<option>NEW</option>");
},2000);
If the selectbox is opened when the timeout finishes, the list isn't updated until you close and reopen the selectbox. Is there a way to make it update the select list while it's still open on Chrome? (I guess on IE too idealy, though that's not required)
I can use replaceWith
to force it to be deselected but this has an ugly effect and I'd prefer if it just changed the list and kept it open.
The actual situation is that my select box is waiting on an ajax call and it's quite easy for the user to open the select box before the ajax is finished.
Chrome and Windows:Hold down Ctrl and click the Reload button. Or Hold down Ctrl and press F5.
Ctrl + F5 is the shortcut to trigger a refresh, which will force the page to reload. To make the browser refresh without relying on the cache, use Shift + Ctrl + F5.
In most browsers, pressing Ctrl+F5 will force the browser to retrieve the webpage from the server instead of loading it from the cache. Firefox, Chrome, Opera, and Internet Explorer all send a “Cache-Control: no-cache” command to the server.
Disabling Auto Refresh Within the Browser To disable auto refresh within the browser, open the Chrome browser, and in the address bar, copy and paste the following: “chrome://discards/”.
There are two pieces to this, you have to blur the drop-down when you update it and then reopen it. Taking away focus is easy, reopening the list is not. I used this technique https://stackoverflow.com/a/10136523/436036 to reopen it.
var showDropdown = function (element) {
var event;
event = document.createEvent('MouseEvents');
event.initMouseEvent('mousedown', true, true, window);
element.dispatchEvent(event);
};
setTimeout(function(){
var focused = false;
if($('#s1').is(":focus")) {
$('#s1').blur();
focused = true;
}
$('#s1').append("<option>NEW</option>");
if(focused) {
showDropdown($('#s1')[0]);
}
},4000);
Here is the fiddle: http://jsfiddle.net/8Ab6c/2/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With