-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
77 lines (61 loc) · 2.48 KB
/
index.html
File metadata and controls
77 lines (61 loc) · 2.48 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
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<br>
<div>
<iframe name="ifrm" id="ifrm" src="http://ChildHost:7080/ChidTest/Child.html" width="800px" height = "360px"></iframe>
<form action="#" id="demoForm">
<label for="greeting">Enter a Greeting: </label>
<input type="text" name="greeting" id="greeting" value="Hello there!">
<br></br>
</form>
</div>
<script type="text/javascript">
//example variable and function for cross-document demo
var counter = 0;
function clearGreeting() {
document.forms['demoForm'].elements['greeting'].value = '';
}
// check for browser support
if ( window.addEventListener ) {
// message handler
window.addEventListener('message', function (e) {
// check message origin
if ( e.origin === 'http://childhost:7080' ) {
var task = e.data['task']; // task received in postMessage
// get reference to iframe window
var win = document.getElementById('ifrm').contentWindow;
switch ( task ) { // postMessage tasks
// obtain height of iframe and send in postMessage
case 'height' :
var ht = document.getElementById('ifrm').offsetHeight;
win.postMessage( {'task': 'height', 'height': ht}, e.origin );
break;
// increment counter variable and send
case 'ctr' :
win.postMessage( {'task': 'ctr', 'counter': ++counter}, e.origin );
break;
// send value of entry in text box (validate first)
case 'val' :
var re = /[^-a-zA-Z!,'?\s]/g; // to filter out unwanted characters
// get reference to greeting text box
var fld = document.forms['demoForm'].elements['greeting'];
var val = fld.value.replace(re, '');
win.postMessage( {'task': 'val', 'val': val}, e.origin );
break;
// clear text box by calling function
case 'clear' :
clearGreeting();
break;
//default:
}
}
}, false);
}
</script>
</body>
</html>