From 03a4f88a22f92e59cde998245b75663427bf8266 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bartosz=20Dziewo=C5=84ski?= Date: Fri, 29 Aug 2014 17:45:48 +0200 Subject: [PATCH] mediawiki.action.view.redirect: Work around a IE 10+ HTML5 history API bug MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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:
Beginning of page
First section
Second section (should always scroll to here)
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 --- .../src/mediawiki.action/mediawiki.action.view.redirect.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/resources/src/mediawiki.action/mediawiki.action.view.redirect.js b/resources/src/mediawiki.action/mediawiki.action.view.redirect.js index c87ff7cbc6..b9aa137e31 100644 --- a/resources/src/mediawiki.action/mediawiki.action.view.redirect.js +++ b/resources/src/mediawiki.action/mediawiki.action.view.redirect.js @@ -38,6 +38,11 @@ // 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 -- 2.20.1