annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
29
18110c461824 js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
1 // http://simonwillison.net/2004/May/26/addLoadEvent/
18110c461824 js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
2 function addLoadEvent(func) {
18110c461824 js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
3 var oldonload = window.onload;
18110c461824 js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
4 if (typeof window.onload != 'function') {
18110c461824 js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
5 window.onload = func;
18110c461824 js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
6 } else {
18110c461824 js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
7 window.onload = function() {
18110c461824 js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
8 if (oldonload) {
18110c461824 js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
9 oldonload();
18110c461824 js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
10 }
18110c461824 js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
11 func();
18110c461824 js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
12 }
18110c461824 js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
13 }
18110c461824 js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
14 }
18110c461824 js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
15
18110c461824 js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
16 var xmlhttp = null;
18110c461824 js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
17
18110c461824 js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
18 function loadXMLDoc(url) {
18110c461824 js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
19 if (window.XMLHttpRequest) {// code for Firefox, Opera, IE7, etc.
18110c461824 js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
20 xmlhttp = new XMLHttpRequest();
18110c461824 js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
21 } else if (window.ActiveXObject) {// code for IE6, IE5
18110c461824 js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
22 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
18110c461824 js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
23 }
18110c461824 js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
24 if (xmlhttp != null) {
18110c461824 js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
25 xmlhttp.onreadystatechange = stateChange;
18110c461824 js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
26 xmlhttp.open("GET",url,true);
18110c461824 js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
27 xmlhttp.send(null);
18110c461824 js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
28 } else {
18110c461824 js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
29 alert("Your browser does not support XMLHTTP.");
18110c461824 js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
30 }
18110c461824 js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
31 }
18110c461824 js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
32
18110c461824 js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
33 function stateChange() {
18110c461824 js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
34 if (xmlhttp.readyState==4) {// 4 = "loaded"
18110c461824 js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
35 document.getElementById('replace').innerHTML = xmlhttp.responseText;
18110c461824 js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
36 }
18110c461824 js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
37 }
18110c461824 js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
38
18110c461824 js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
39 addLoadEvent(function () {
18110c461824 js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
40 if (navigator.appVersion.indexOf("Win")!=-1) {
18110c461824 js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
41 loadXMLDoc("win.html");
18110c461824 js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
42 }
18110c461824 js: loading another content if OS is Win
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
43 });