1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script>
function openfile(Name,response){
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
response({"filename":Name,"text":xmlhttp.responseText});
}
}
xmlhttp.open("GET",Name,true);
xmlhttp.send();
}
function sendfile(response){
//http://stackoverflow.com/questions/3076414/ways-to-circumvent-the-same-origin-policy
window.parent.postMessage(response,'*');
}
//http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&#]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
function servefile(){
var request = getParameterByName('file');
if(request!="")openfile(request,sendfile);
else openfile("parts.json",sendfile);
}
</script>
</head>
<body onload="servefile()">
this is a webtronics javascript server.
request ?file=parts.json for list of files.
</body>
</html>
|