forked from Tencent/vConsole
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo3.php
49 lines (45 loc) · 1.52 KB
/
demo3.php
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
<?php
// 这个demo用于测试CSP的规则
$nonce = rand(10000, 99999);
header("Content-Security-Policy: script-src 'self' 'unsafe-inline' 'unsafe-eval' 'nonce-" . $nonce . "';");
?><!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, viewport-fit=cover">
<title>vConsole/Demo3</title>
<link href="./lib/weui.min.css" rel="stylesheet"/>
<link href="./lib/demo.css" rel="stylesheet"/>
<!-- 引入vConsole的JS库 -->
<script src="../dist/vconsole.min.js" nonce="<?php echo $nonce; ?>"></script>
<script nonce="<?php echo $nonce; ?>">
// 初始化vConsole
window.vConsole = new window.VConsole();
</script>
</head>
<body>
<div class="page">
<h1 class="page_title">Demo 3</h1>
<a href="javascript:;" class="weui_btn weui_btn_primary js_btn_log">Hello World</a>
</div>
<div class="weui_toptips weui_notice" id="js_tips">已打印log</div>
</body>
<script nonce="<?php echo $nonce; ?>">
document.querySelector('.js_btn_log').addEventListener('touchend', function(e) {
// 打印log时无须判断是否为dev_mode,
// 未加载vConsole时,console.log()不会显示到前台
console.log('Hello World');
showTips();
});
// 用于页面内展示顶部tips
let tipsTimer;
const showTips = () => {
tipsTimer && clearTimeout(tipsTimer);
const $tips = document.querySelector('#js_tips');
$tips.style.display = 'block';
tipsTimer = setTimeout(() => {
$tips.style.display = 'none';
}, 1500);
};
</script>
</html>