Chrome page auto scroll to select multiple with option selected

2

When using the multiple attribute, the page when loaded loads the last <select/> that contains a option with the selected attribute:

Example in JSFiddle

<p>No Google Chrome a página não fica aqui...</p>
<form style="padding-top:1000px;">
    <p>No Google Chrome desliza para aqui...</p>
    <select multiple="multiple">
        <option selected="selected">1</option>
        <option>2</option>
    </select>
</form>

form{
    padding-top:1000px;
}
<p>No Google Chrome a página não fica aqui...</p>
<form>
    <p>No Google Chrome desliza para aqui...</p>
    <select multiple="multiple">
        <option selected="selected">1</option>
        <option>2</option>
    </select>
</form>

This same problem is also reported for Chromium although the indication is that it appears only in some versions:

Question

How can I work around this problem so that the website has the same behavior in all browsers?

Tests where the problem does not occur:

  • Chromium Version 37.0.2062.120 Built on Ubuntu 14.04, running on LinuxMint 17 (64-bit)
  • Mozilla firefox 32.0.3 for Linux Mint - mint - 1.0
  • Internet Explorer 11 - Version 11.0.9600.17351 - Update 11.0.13 running on Windows 8.1

Successful bug playback:

  • Google Chrome - Version 38.0.2125.111 m running on Windows 8.1
asked by anonymous 04.11.2014 / 21:59

1 answer

1

As of today, after updating the Google Chrome browser for the "39.0.2171.95 m" version running on Windows 8.1 64Bit the problem no longer exists.

At the time, I tried to get around the bug in the version indicated in the question and in others as seen in bug reports also indicated in the question, I ended up applying the following workaround :

See example in JSFiddle functional only in versions where the bug is noticed

JavaScript

// Quando o documento está pronto
document.addEventListener("DOMContentLoaded", function(event) { 

        // ... outras ações primeiro ...


        var isChrome = window.chrome;    // identifica se é o Google Chrome
        if (isChrome) {                  // se for
            window.scrollTo(0,0);        // força o scroll para o topo da janela
        }
});

jQuery

// Quando o documento está pronto
$(document).ready(function() {

    // ... outras ações primeiro ...


    var isChrome = window.chrome;    // identifica se é o Google Chrome
    if (isChrome) {                  // se for
        window.scrollTo(0,0);        // força o scroll para o topo da janela
    }
});
    
26.12.2014 / 14:02