Skip to content

Commit

Permalink
#733: adding UA sniff for history support
Browse files Browse the repository at this point in the history
  • Loading branch information
hay committed Nov 13, 2012
1 parent d7c7393 commit 45de935
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion feature-detects/history.js
Original file line number Diff line number Diff line change
@@ -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;
}
}
});

0 comments on commit 45de935

Please sign in to comment.