-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathiframes.js
36 lines (35 loc) · 1.12 KB
/
iframes.js
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
/**
* A utility module for communication with iframes
*
* @module c4/iframes
*/
define(function() {
return {
/**
* Sends a message to all iframes embedded in the current window.
* @param {Object} msg The message to send.
*/
sendMsgAll: function(msg) {
var iframes = document.getElementsByTagName('iframe');
for (var i = 0; i < iframes.length; i++) {
iframes[i].contentWindow.postMessage(msg, '*');
}
},
/**
* Sends a message to a list of embedded iframes.
* @param {Object} msg The message to send.
* @param {Array} ids of destination frames.
*/
sendMsg: function(msg, ids){
if(Array.isArray(ids)){
var len = ids.length;
for (var i = 0; i < len; i++) {
var iframe = document.getElementById(ids[i]);
if(iframe != null && iframe.tagName === 'IFRAME'){
iframe.contentWindow.postMessage(msg, '*');
}
}
}
}
};
});