-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
51 lines (51 loc) · 1.81 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Service Worker Demo</title>
</head>
<body>
<span>图片头像</span>
<img src="./img/react.png" alt="">
<hr/>
<span>Ajax Get 数据</span>
<ul id="list"></ul>
<script src="js/jquery_v1.js"></script>
<script src="js/index_v1.js"></script>
<script type="text/javascript">
$.ajax('/getList').done(function (res) {
res.data.forEach(item => {
$('#list').append(`<li>${item}</li>`)
});
})
let body = document.querySelector('body');
let myImage = new Image();
imgLoad('./img/react.png').then((response) => {
console.log(response);
var imageURL = window.URL.createObjectURL(response);
myImage.src = imageURL;
body.appendChild(myImage);
}, (Error) => {
console.log(Error);
})
</script>
<script type="text/javascript">
// serviceWorker 注册
if ('serviceWorker' in navigator) {
// navigator.serviceWorker.register('./sw.js', {scope: './'})
// .then(function (reg) {
// console.log('register sw.js success');
// })
// .catch(function (err) {
// console.error('register sw.js failed');
// })
window.addEventListener('load', () => {
console.log('load');
navigator.serviceWorker.register('./sw.js');
})
} else {
console.log('service worker is not work');
}
</script>
</body>
</html>