Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
executable file
·60 lines (45 loc) · 1.83 KB
/
Copy pathindex.html
File metadata and controls
executable file
·60 lines (45 loc) · 1.83 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
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf8">
<script language="javascript">
var callbacks = {};
var random = Math.floor(Math.random() * 2000000000);
function pokeNative() {
//业务参数
var command = {
'method':'post',
'url':'https:www.baidu.com'
}
//封装层参数
var service = 'WKFetchPlugin';
var action = 'nativeFentch';
var callbackId = service + random++;
callbacks[callbackId] = {};
var actionArgs = {
'id' : callbackId, //id
'service' : service,
'action' : action,
'actionArgs' :command
};
//调用客户端
window.webkit.messageHandlers.WKWKJSBridge.postMessage(JSON.stringify(actionArgs));
}
function fetchComplete(id,status,result) {
asyncAlert(result);
document.getElementById("returnValue").value = (id) + result;
}
function asyncAlert(content) {
setTimeout(function(){
alert(content);
},1);
}
</script>
</head>
<body>
<h1>按钮调用</h1>
<input type="button" value="网络请求" onclick="pokeNative()" />
<h1>回调结果展示区</h1>
<textarea id ="returnValue" type="value" rows="5" cols="40">
</textarea>
</body>
</html>