How to refactor old browser detection JavaScript?
Remarks

It sure is an interesting, hackery approach. Taken into account that this code must be compatible with archaic browsers, I would say it's rather fine. Few remarks:


For readability while() with no body could be rewritten to do {...} while().
Fail safe v &lt;= 9 to avoid potential infinite loop could be added, in case something would change regarding browsers' behavior.
Naming could be better: div could become element to abstract used tag from the purpose of this variable's existence, v could become less-cryptic version.
Variable undef is unnecessary, it's only use occurrence can be replaced with false.
Formatting issues.
Inconsistent indentation, bracket policy and quotation marks.
Unnecessary addition of level of indentation; below ifs can be combined:

if (ie) 
{
    if (ie &lt; 9)
        {

If you would use single quotation marks in your alert(), you would have to perform only one escaping, instead of two.
window.parent should be replaced with window.top since parent could be iframe as well.


Rewrite

(untested for positive cases)


var ieVersion = (function() {
  var element = document.createElement('span');
  var version = 3;

  do {
    element.innerHTML = '&lt;!--[if gt IE ' + (++version) + ']&gt;&lt;span&gt;&lt;/span&gt;&lt;![endif]--&gt;';
  }
  while (element.getElementsByTagName('span')[0] &amp;&amp; version &lt;= 9);

  return version &gt; 4 ? version : false;
}());

if (ieVersion &amp;&amp; ieVersion &lt; 9) {
  alert('You are running an older version of Microsoft Internet Explorer:\r\nVersion ' + ie.toFixed(1) + ', which is NOT supported.\r\n\r\nPlease upgrade your web browser to its latest version, or if you\'re still using Windows XP, to Google Chrome, Mozilla Firefox, Apple Safari, or Opera, to view this website, properly.\r\n\r\nClick "OK" to read instructions on how to download and install a newer, more compatible, web browser.');
  window.top.location.href = '/libs/old_browser_detect/current/upgrade_browser.php';
}




Different approaches

Feature-detection

I think it would be best to achieve your goal by using regular feature-detection based method:



var ieVersion = (function getLegacyIEVersion() {
  if (!document.compatMode) { return 5; }
  if (!window.XMLHttpRequest) { return 6; }
  if (!document.querySelector) { return 7; }
  if (!document.addEventListener) { return 8; }
  //if (!window.atob) { return 9; }
  return false;
})();

var IEThreshold = 9;
if (ieVersion !== false &amp;&amp; ieVersion &lt; IEThreshold) {
  console.log('Legacy IE');
}
else {
  console.log('Not a legacy IE');
}
/* Demo console styling */
.as-console-wrapper { top: 0; }




Conditional compilation

Another way of achieving the same, would be to use conditional compilation to detect JS engine version. Change ieVersion() function from previous code to:

var ieVersion = /*@cc_on (function() {
  switch(@_jscript_version) {
    case 1.0: return 3; break;
    case 3.0: return 4; break;
    case 5.0:
    case 5.1: return 5; break;
    case 5.5: return 5.5; break;
    case 5.6: return 6; break;
    case 5.7: return 7; break;
    case 5.8: return 8; break;
    case 9: return 9; break;
    case 10: return 10; break;
  }
})() || @*/ false;


Note however, that this method uses @_jscript_version which returns version of JS engine of the browser itself, while in cases of running in compatibility mode it would be desirable to get an actually used engine version, instead. Also, minifiers would get rid of this code, since for browsers other than IE &lt; 11 this is just a comment.