history.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*!
  2. {
  3. "name": "History API",
  4. "property": "history",
  5. "caniuse": "history",
  6. "tags": ["history"],
  7. "authors": ["Hay Kranen", "Alexander Farkas"],
  8. "notes": [{
  9. "name": "W3C Spec",
  10. "href": "https://www.w3.org/TR/html51/browsers.html#the-history-interface"
  11. }, {
  12. "name": "MDN Docs",
  13. "href": "https://developer.mozilla.org/en-US/docs/Web/API/window.history"
  14. }],
  15. "polyfills": ["historyjs", "html5historyapi"]
  16. }
  17. !*/
  18. /* DOC
  19. Detects support for the History API for manipulating the browser session history.
  20. */
  21. define(['Modernizr'], function(Modernizr) {
  22. Modernizr.addTest('history', function() {
  23. // Issue #733
  24. // The stock browser on Android 2.2 & 2.3, and 4.0.x returns positive on history support
  25. // Unfortunately support is really buggy and there is no clean way to detect
  26. // these bugs, so we fall back to a user agent sniff :(
  27. var ua = navigator.userAgent;
  28. // We only want Android 2 and 4.0, stock browser, and not Chrome which identifies
  29. // itself as 'Mobile Safari' as well, nor Windows Phone (issue #1471).
  30. if ((ua.indexOf('Android 2.') !== -1 ||
  31. (ua.indexOf('Android 4.0') !== -1)) &&
  32. ua.indexOf('Mobile Safari') !== -1 &&
  33. ua.indexOf('Chrome') === -1 &&
  34. ua.indexOf('Windows Phone') === -1 &&
  35. // Since all documents on file:// share an origin, the History apis are
  36. // blocked there as well
  37. location.protocol !== 'file:'
  38. ) {
  39. return false;
  40. }
  41. // Return the regular check
  42. return (window.history && 'pushState' in window.history);
  43. });
  44. });