ie-emulation-modes-warning.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // NOTICE!! DO NOT USE ANY OF THIS JAVASCRIPT
  2. // IT'S JUST JUNK FOR OUR DOCS!
  3. // ++++++++++++++++++++++++++++++++++++++++++
  4. /*!
  5. * Copyright 2014-2015 The Bootstrap Authors
  6. * Copyright 2014-2015 Twitter, Inc.
  7. *
  8. * Licensed under the Creative Commons Attribution 3.0 Unported License. For
  9. * details, see https://creativecommons.org/licenses/by/3.0/.
  10. */
  11. // Intended to prevent false-positive bug reports about Bootstrap not working properly in old versions of IE due to folks testing using IE's unreliable emulation modes.
  12. (function () {
  13. 'use strict'
  14. function emulatedIEMajorVersion() {
  15. var groups = /MSIE ([0-9.]+)/.exec(window.navigator.userAgent)
  16. if (groups === null) {
  17. return null
  18. }
  19. var ieVersionNum = parseInt(groups[1], 10)
  20. var ieMajorVersion = Math.floor(ieVersionNum)
  21. return ieMajorVersion
  22. }
  23. function actualNonEmulatedIEMajorVersion() {
  24. // Detects the actual version of IE in use, even if it's in an older-IE emulation mode.
  25. // IE JavaScript conditional compilation docs: https://msdn.microsoft.com/library/121hztk3%28v=vs.94%29.aspx
  26. // @cc_on docs: https://msdn.microsoft.com/library/8ka90k2e%28v=vs.94%29.aspx
  27. var jscriptVersion = new Function('/*@cc_on return @_jscript_version; @*/')() // eslint-disable-line no-new-func
  28. if (jscriptVersion === undefined) {
  29. return 11 // IE11+ not in emulation mode
  30. }
  31. if (jscriptVersion < 9) {
  32. return 8 // IE8 (or lower; haven't tested on IE<8)
  33. }
  34. return jscriptVersion // IE9 or IE10 in any mode, or IE11 in non-IE11 mode
  35. }
  36. var ua = window.navigator.userAgent
  37. if (ua.indexOf('Opera') > -1 || ua.indexOf('Presto') > -1) {
  38. return // Opera, which might pretend to be IE
  39. }
  40. var emulated = emulatedIEMajorVersion()
  41. if (emulated === null) {
  42. return // Not IE
  43. }
  44. var nonEmulated = actualNonEmulatedIEMajorVersion()
  45. if (emulated !== nonEmulated) {
  46. window.alert('WARNING: You appear to be using IE' + nonEmulated + ' in IE' + emulated + ' emulation mode.\nIE emulation modes can behave significantly differently from ACTUAL older versions of IE.\nPLEASE DON\'T FILE BOOTSTRAP BUGS based on testing in IE emulation modes!')
  47. }
  48. }())