mediawiki.action.view.redirect: Work around a IE 10+ HTML5 history API bug
authorBartosz Dziewoński <matma.rex@gmail.com>
Fri, 29 Aug 2014 15:45:48 +0000 (17:45 +0200)
committerBartosz Dziewoński <matma.rex@gmail.com>
Fri, 29 Aug 2014 16:05:49 +0000 (18:05 +0200)
Internet Explorer 10 and 11 doesn't scroll the page to given fragment
when `history.replaceState` is used. Changing `location.hash` afterwards,
even though it's a no-op, results in the page scrolling properly.

Minimal broken test case:
  <style>div { height: 1000px; border: 1px solid blue; }</style>
  <script>history.replaceState( /*data=*/ history.state, /*title=*/ document.title, /*url=*/ '#second' );</script>
  <div id="start">Beginning of page</div>
  <div id="first">First section</div>
  <div id="second">Second section (should always scroll to here)</div>

JSFiddle test case:
* Works:        http://jsfiddle.net/rv9w9wr5/
* Doesn't work: http://jsfiddle.net/e6fy0mar/
* Works again:  http://jsfiddle.net/o8vc5grf/

It is also interesting to try visiting the test cases with a fragment
already in the URL. It seems that the history API in IE updates the
page's address, but doesn't update "fragment state" – the broken,
second testcase scrolls to #first in spite of displaying #second in
the address bar.

* http://fiddle.jshell.net/rv9w9wr5/show/light/#first
* http://fiddle.jshell.net/e6fy0mar/show/light/#first
* http://fiddle.jshell.net/o8vc5grf/show/light/#first

Bug: 70176
Change-Id: I19221a25a3167e94c2aa412bfdd8d0d8c57c5076

resources/src/mediawiki.action/mediawiki.action.view.redirect.js

index c87ff7c..b9aa137 100644 (file)
                // This will also cause the browser to scroll to given fragment
                history.replaceState( /*data=*/ history.state, /*title=*/ document.title, /*url=*/ canonical );
 
+               // …except for IE 10 and 11. Prod it with a location.hash change.
+               if ( shouldChangeFragment && profile.name === 'msie' && profile.versionNumber >= 10 ) {
+                       location.hash = fragment;
+               }
+
        } else if ( shouldChangeFragment ) {
                if ( profile.layout === 'webkit' && profile.layoutVersion < 420 ) {
                        // Released Safari w/ WebKit 418.9.1 messes up horribly