-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
43 lines (39 loc) · 1.38 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>JS message</title>
<script>
function displayResponse(response) {
responseField = document.getElementById("test-response");
responseField.value = response.data;
}
function postWindowMessage(message) {
window.postMessage(message);
}
window.addEventListener('message', displayResponse, false);
window.onload = function () {
var form = document.getElementById("message-form"),
messageField = document.getElementById("test-message");
form.onsubmit = function () {
var message = messageField.value
console.log(message);
if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.messageHandler) {
window.webkit.messageHandlers.messageHandler.postMessage({
"message": message
});
}
return false;
};
};
</script>
</head>
<body>
<form id="message-form" action="/">
<input type="text" id="test-message" value="Hello world!">
<input type="submit" value="Post Message">
<br>
<input type="text" id="test-response" value="">
</form>
</body>
</html>