-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjson.html
236 lines (224 loc) · 8.92 KB
/
json.html
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
<!DOCTYPE html>
<html>
<body>
<!-- Other Window Methods
Some other methods:
window.open() - open a new window
window.close() - close the current window
window.moveTo() - move the current window
window.resizeTo() - resize the current window -->
<p id="screen"></p>
<script>
var funcRepeat = setInterval(hTime, 500);
function hTime() {
var w = window.innerWidth ||
document.documentElement.clientWidth ||
document.body.clientWidth;
var h = window.innerHeight ||
document.documentElement.clientHeight ||
document.body.clientHeight;
var x = document.getElementById("screen");
x.innerHTML = "Browser inner window width: " + w + ", height: " + h + ".";
}
</script>
<p id="width"></p>
<p id="height"></p>
<p id="availWidth"></p>
<p id="availHeight"></p>
<script>
var screenSizeRepeat = setInterval(screenSize, 1000);
function screenSize() {
document.getElementById("width").innerHTML = "Screen width is " + screen.width;
document.getElementById("height").innerHTML = "Screen height is " + screen.height;
document.getElementById("availWidth").innerHTML = "Available screen width is " + screen.availWidth;
document.getElementById("availHeight").innerHTML = "Available screen height is " + screen.availHeight;
}
</script>
<p id="colorDepth"></p>
<p id="pixelDepth"></p>
<script>
document.getElementById("colorDepth").innerHTML = "Screen color depth is " + screen.colorDepth;
document.getElementById("pixelDepth").innerHTML = "Screen pixel depth is " + screen.pixelDepth;
</script>
<h2>JavaScript</h2>
<h3>The window.location object</h3>
<input type="button" value="Load new document" onclick="newDoc()">
<script>
function newDoc() {
window.location.assign("https://matviy.pp.ua")
}
</script>
<h2>JavaScript Alert</h2>
<button onclick="myFunction1()">Try it</button>
<script>
function myFunction1() {
alert("I am an alert box!");
}
</script>
<h2>JavaScript Confirm Box</h2>
<button onclick="myFunction2()">Try it</button>
<p id="confirmBox"></p>
<script>
function myFunction2() {
var txt;
if (confirm("Press a button!")) {
txt = "You pressed OK!";
} else {
txt = "You pressed Cancel!";
}
document.getElementById("confirmBox").innerHTML = txt;
}
</script>
<h2>JavaScript Prompt</h2>
<button onclick="myFunction3()">Try it</button>
<p id="prompt"></p>
<script>
function myFunction3() {
var txt;
var person = prompt("Please enter your name:", "Harry Potter");
if (person == null || person == "") {
txt = "User cancelled the prompt.";
} else {
txt = "Hello " + person + "! How are you today?";
}
document.getElementById("prompt").innerHTML = txt;
}
</script>
<h2>JavaScript</h2>
<p>Line-breaks in a popup box.</p>
<button onclick="alert('Hello\nHow are you?')">Try it</button>
<p>Click "Try it". Wait 3 seconds, and the page will alert "Hello".</p>
<button onclick="setTimeout(myFunction4, 3000);">Try it</button>
<script>
function myFunction4() {
alert('Hello');
}
</script>
<p>Click "Try it". Wait 3 seconds. The page will alert "Hello".</p>
<p>Click "Stop" to prevent the first function to execute.</p>
<p>(You must click "Stop" before the 3 seconds are up.)</p>
<button onclick="myVar = setTimeout(myFunction5, 3000)">Try it</button>
<button onclick="clearTimeout(myVar)">Stop it</button>
<script>
function myFunction5() {
alert("Hello");
}
</script>
<p>A script on this page starts this clock:</p>
<p id="time"></p>
<script>
var myVar = setInterval(myTimer, 1000);
function myTimer() {
var d = new Date();
document.getElementById("time").innerHTML = d.toLocaleTimeString();
}
</script>
<p>A script on this page starts this clock:</p>
<p id="stopTime"></p>
<button onclick="clearInterval(myTime)">Stop time</button>
<script>
var myTime = setInterval(myTimer, 1000);
function myTimer() {
var stopTime = new Date();
document.getElementById("stopTime").innerHTML = stopTime.toLocaleTimeString();
}
</script>
<p>A script on this page starts this clock:</p>
<p id="demo"></p>
<button onclick="clearInterval(myVar)">Stop time</button>
<script>
var myVar = setInterval(myTimer, 1000);
function myTimer() {
var d = new Date();
document.getElementById("demo").innerHTML = d.toLocaleTimeString();
}
</script>
<br>
<h2>JavaScript</h2>
<h3>The window.location object</h3>
<p id="href"></p>
<p id="hostname"></p>
<p id="pathname"></p>
<p id="protocol"></p>
<p id="port"></p>
<p><b>Note: </b>If the port number is default (80 for http and 443 for https), most browsers will display 0 or nothing.</p>
<script>
document.getElementById("href").innerHTML = "The full URL of this page is:<br>" + window.location.href;
document.getElementById("hostname").innerHTML = "Page hostname is: " + window.location.hostname;
document.getElementById("pathname").innerHTML = "Page path is: " + window.location.pathname;
document.getElementById("protocol").innerHTML = "The page protocol is: " + window.location.protocol;
document.getElementById("port").innerHTML = "The URL port number of the current page is: " + window.location.port;
</script>
<br>
<h2>The Navigator Object</h2>
<p>The appName property returns the application name of the browser:</p>
<p id="appName"></p>
<p>Strange enough, "Netscape" is the application name for both IE11, Chrome, Firefox, and Safari.</p>
<br>
<p>The appVersion property returns version information about the browser:</p>
<p id="appVersion"></p>
<p>The userAgent property returns the user-agent header sent by the browser to the server:</p>
<p id="userAgent"></p>
<p>The platform property returns the browser platform (operating system):</p>
<p id="platform"></p>
<p>The language property returns the browser's language:</p>
<p id="language"></p>
<p>The onLine property returns true if the browser is online:</p>
<p id="onLine"></p>
<p>The javaEnabled() method returns true if Java is enabled:</p>
<p id="javaEnabled"></p>
<script>
document.getElementById("appName").innerHTML = "navigator.appName is " + navigator.appName;
document.getElementById("appVersion").innerHTML = navigator.appVersion;
document.getElementById("userAgent").innerHTML = navigator.userAgent;
document.getElementById("platform").innerHTML = "navigator.platform is " + navigator.platform;
document.getElementById("language").innerHTML = "navigator.language is " + navigator.language;
document.getElementById("onLine").innerHTML = "navigator.onLine is " + navigator.onLine;
document.getElementById("javaEnabled").innerHTML = "javaEnabled is " + navigator.javaEnabled();
</script>
<br>
<h2>Use the XMLHttpRequest to get the content of a file.</h2>
<p>The content is written in JSON format, and can easily be converted into a JavaScript object.</p>
<p id="test"></p>
<script>
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var a = JSON.parse(this.responseText),
b,buy,sale;
b += a[0].ccy + "\n";
b += a[0].base_ccy + "<br>";
buy = (a[0].buy * 1);
b += buy.toFixed(2) + "\n";
sale = (a[0].sale * 1);
b += sale.toFixed(2) + "\n";
b += "<br>";
b += a[1].ccy + "\n";
b += a[1].base_ccy + "<br>";
buy = (a[1].buy * 1);
b += buy.toFixed(2) + "\n";
sale = (a[1].sale * 1);
b += sale.toFixed(2) + "\n";
b += "<br>";
b += a[2].ccy + "\n";
b += a[2].base_ccy + "<br>";
buy = (a[2].buy * 1);
b += buy.toFixed(2) + "\n";
sale = (a[2].sale * 1);
b += sale.toFixed(2) + "\n";
b += "<br>";
b += a[3].ccy + "\n";
b += a[3].base_ccy + "<br>";
buy = (a[3].buy * 1);
b += buy.toFixed(2) + "\n";
sale = (a[3].sale * 1);
b += sale.toFixed(2) + "\n";
document.getElementById("test").innerHTML = b;
}
};
xmlhttp.open("GET", "https://api.privatbank.ua/p24api/pubinfo?json&exchange&coursid=5", true);
xmlhttp.send();
</script>
<p>Take a look at <a href="https://api.privatbank.ua/p24api/pubinfo?json&exchange&coursid=5" target="_blank">https://api.privatbank.ua/p24api/pubinfo?json&exchange&coursid=5</a></p>
</body>
</html>