forked from luffyjet/WebViewJavaScriptBridge
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExampleApp.html
More file actions
105 lines (84 loc) · 2.69 KB
/
ExampleApp.html
File metadata and controls
105 lines (84 loc) · 2.69 KB
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
<!doctype html>
<html>
<head>
<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0, maximum-scale=1.0">
<style type='text/css'>
html {
font-family: Helvetica;
color: #222;
}
h1 {
color: steelblue;
font-size: 24px;
margin-top: 24px;
}
button {
margin: 0 3px 10px;
font-size: 12px;
}
.logLine {
border-bottom: 1px solid #ccc;
padding: 4px 2px;
font-family: courier;
font-size: 11px;
}
</style>
<script src="js/ccnativeapi.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
//测试代码----------------------
var uniqueId = 1;
function log(message, data) {
var log = document.getElementById('log');
var el = document.createElement('div');
el.className = 'logLine';
el.innerHTML = uniqueId++ + '. ' + message + ':<br/>' + JSON.stringify(data);
if(log.children.length) {
log.insertBefore(el, log.children[0]);
} else {
log.appendChild(el);
}
}
//--------------------
function chooseImage() {
ccapi.chooseImage({
count: 1, // 数量
success: function(res) {
var localIds = res.localIds; // 返回选定照片的本地ID列表,localId可以作为img标签的src属性显示图片
console.log("chooseImage response: " + localIds.toString());
console.log("chooseImage response all: " + JSON.stringify(res));
var imgTag = document.getElementById("ts_img");
imgTag.src = localIds[0];
log('Native responding with ', res);
}
});
}
function deviceInfo() {
ccapi.deviceInfo({
full: false, // 可以指定全部获取,还是只要基本信息,默认全部
success: function(res) {
// var data = JSON.parse(res);
console.log("appName: " + res.appName);
console.log("appVersion: " + res.appVersion);
console.log("all: " + JSON.stringify(res));
log('Native responding with ', res);
}
});
}
function jsCallNative() {
window.WebViewJavascriptBridge.callHandler('abs', '{\'msg\':\'js call native test\'}', function(res) {
console.log("Native response " + res);
log('Native responding with ', res);
});
}
</script>
</head>
<body>
<h1>WebViewJavascriptBridge Demo</h1>
<div id='buttons'></div>
<div id='log'></div>
<input type="button" id="callNative" value="调用Native测试" onclick="jsCallNative()" />
<input type="button" id="chooseimg" value="选图" onclick="chooseImage()" />
<input type="button" id="deviceinfo" value="设备信息" onclick="deviceInfo()" />
<img src="" id="ts_img" width="100%" height="auto"/>
</body>
</html>