From 45de935edf460ac56fcc3f337885ee115f725101 Mon Sep 17 00:00:00 2001 From: Hay Kranen Date: Tue, 13 Nov 2012 11:42:18 +0100 Subject: [PATCH 1/2] #733: adding UA sniff for history support --- feature-detects/history.js | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/feature-detects/history.js b/feature-detects/history.js index 718675eb55..e56665d7c3 100644 --- a/feature-detects/history.js +++ b/feature-detects/history.js @@ -1,4 +1,29 @@ +// Test for the history API // http://dev.w3.org/html5/spec/history.html#the-history-interface +// by Hay Kranen < http://github.com/hay > -Modernizr.addTest('history', !!(window.history && history.pushState)); +Modernizr.addTest('history', function() { + // Issue #733 + // The stock browser on Android < 3.0 returns positive on history support + // Unfortunately support is really buggy and there is no clean way to detect + // these bugs, so we fall back to a user agent sniff :( + var ua = navigator.userAgent; + var properCheck = !!(window.history && history.pushState); + + if (ua.indexOf("Android") === -1) { + // No Android, simply return the 'proper' check + return properCheck; + } else { + // We need to check for the stock browser (which identifies itself + // as 'Mobile Safari'), however, Chrome on Android gives the same + // identifier (and does support history properly), so check for that too + if (ua.indexOf("Mobile Safari") !== -1 && ua.indexOf("Chrome") === -1) { + // Buggy implementation, always return false + return false; + } else { + // Chrome, return the proper check + return properCheck; + } + } +}); \ No newline at end of file From cb40fa28eeb0c3b71e3d52700a7c504a52f46590 Mon Sep 17 00:00:00 2001 From: Hay Kranen Date: Tue, 13 Nov 2012 17:48:23 +0100 Subject: [PATCH 2/2] only check for version of Android between 2 and 3 --- feature-detects/history.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/feature-detects/history.js b/feature-detects/history.js index e56665d7c3..00872fc3a8 100644 --- a/feature-detects/history.js +++ b/feature-detects/history.js @@ -11,7 +11,7 @@ Modernizr.addTest('history', function() { var ua = navigator.userAgent; var properCheck = !!(window.history && history.pushState); - if (ua.indexOf("Android") === -1) { + if (ua.indexOf("Android 2") === -1) { // No Android, simply return the 'proper' check return properCheck; } else {