view src/en/javascript/main.js @ 29:18110c461824

js: loading another content if OS is Win
author Alexander Solovyov <piranha@piranha.org.ua>
date Mon, 16 Feb 2009 00:04:58 +0200
parents
children baf1530ba0b0
line wrap: on
line source

// http://simonwillison.net/2004/May/26/addLoadEvent/
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

var xmlhttp = null;

function loadXMLDoc(url) {
    if (window.XMLHttpRequest) {// code for Firefox, Opera, IE7, etc.
        xmlhttp = new XMLHttpRequest();
    } else if (window.ActiveXObject) {// code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    if (xmlhttp != null) {
        xmlhttp.onreadystatechange = stateChange;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    } else {
        alert("Your browser does not support XMLHTTP.");
    }
}

function stateChange() {
    if (xmlhttp.readyState==4) {// 4 = "loaded"
        document.getElementById('replace').innerHTML = xmlhttp.responseText;
    }
}

addLoadEvent(function () {
    if (navigator.appVersion.indexOf("Win")!=-1) {
        loadXMLDoc("win.html");
    }
});