Skip to content

Commit

Permalink
Merge pull request #92 from basil79/no-message-when-in-iframe
Browse files Browse the repository at this point in the history
fixed message when ads-manager is inside an iframe
  • Loading branch information
basil79 committed Feb 10, 2023
2 parents 05b23b1 + 983b39c commit 26d4634
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 6 deletions.
2 changes: 1 addition & 1 deletion dist/ads-manager.es.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ads-manager.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ads-manager",
"version": "1.2.5",
"version": "1.2.6",
"description": "HTML5 Video Ads Manager based on @dailymotion/vast-client",
"publishConfig": {
"registry": "https://registry.npmjs.org"
Expand Down
12 changes: 12 additions & 0 deletions public/iframe.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Ads Manager</title>
</head>
<body>

<iframe src="index.html" width="100%" height="600px"></iframe>

</body>
</html>
4 changes: 2 additions & 2 deletions public/js/ads-manager.js

Large diffs are not rendered by default.

16 changes: 15 additions & 1 deletion src/ads-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,21 @@ AdsManager.prototype.loadCreativeAsset = function(fileURL) {
this._vpaidIframe.contentWindow.document.open();
this._vpaidIframe.contentWindow.document.write(`
<script>function sendMessage(msg) {
window.parent.postMessage('adm:${this._requestId}://' + JSON.stringify(msg), '*'); }
var postMsg = 'adm:${this._requestId}://' + JSON.stringify(msg);
window.parent.postMessage(postMsg, '*');
if(window.parent !== window) {
window.postMessage(postMsg,'*');
}
try {
if(window.parent !== window.top) {
window.top.postMessage(postMsg,'*');
for (var i = 0; i < window.top.frames.length; i++) {
try {
window.top.frames[i].postMessage(postMsg,'*');
} catch(e) {}
}
}
} catch(e) {} }
\x3c/script>
<script type="text/javascript" onload="sendMessage('load')" onerror="sendMessage('error')" src="${fileURL}"> \x3c/script>
`);
Expand Down

0 comments on commit 26d4634

Please sign in to comment.