-
Notifications
You must be signed in to change notification settings - Fork 0
/
ss2.html
43 lines (41 loc) · 1.33 KB
/
ss2.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Cat Image</title>
<style>
body {
text-align: center;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #f0f0f0;
}
img {
max-width: 100%;
height: auto;
}
</style>
</head>
<body>
<img id="catImage" src="https://api.thecatapi.com/v1/images/search" alt="Cat Image">
<script>
async function fetchCatImage() {
try {
const response = await fetch('https://api.thecatapi.com/v1/images/search');
const data = await response.json();
const catImageUrl = data[0].url; // Extract the image URL from the JSON response
document.getElementById('catImage').src = catImageUrl; // Set the image URL to the img element
} catch (error) {
console.error('Error fetching cat image:', error);
}
}
// Fetch the cat image when the page loads
window.onload = fetchCatImage;
</script>
</body>
</html>