• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1var fileXHREnabled = function() {
2  var xhr = new XMLHttpRequest();
3  try {
4    xhr.onreadystatechange = function() {};
5    xhr.onerror = function() {};
6    xhr.open("GET", "nothing.xml", true);
7    xhr.send(null);
8  } catch (e) {
9    return false;
10  }
11
12  xhr.abort();
13  return true;
14}();
15
16// Regenerate page if we are passed the "?regenerate" search param
17// or if the user-agent is chrome AND the document is being served
18// from the file:/// scheme.
19if (window.location.search == "?regenerate" ||
20    (navigator.userAgent.indexOf("Chrome") > -1) &&
21    (window.location.href.match("^file:")) &&
22    fileXHREnabled)    {
23
24  // Hide body content initially to minimize flashing.
25  document.write('<style id="hider" type="text/css">');
26  document.write('body { display:none!important; }');
27  document.write('</style>');
28
29  window.onload = window.renderPage;
30
31  window.postRender = function() {
32    var elm = document.getElementById("hider");
33    elm.parentNode.removeChild(elm);
34
35    // Since populating the page is done asynchronously, the DOM doesn't exist
36    // when the browser tries to resolve any #anchors in the URL. So we reset
37    // the URL once we're done, which forces the browser to scroll to the anchor
38    // as it normally would.
39    if (location.hash.length > 1)
40      location.href = location.href;
41  }
42} else if ((navigator.userAgent.indexOf("Chrome") > -1) &&
43           (window.location.href.match("^file:")) &&
44            !fileXHREnabled) {
45  window.onload = function() {
46    // Display the warning to use the --allow-file-access-from-files.
47    document.getElementById("devModeWarning").style.display = "block";
48  }
49}
50