Tag: postmessage

用jquery设置fancybox高度

我想在我的页面上显示一个fancybox,显示一个iframe,其中包含另一个具有动态高度的域的来源(因为在iframe中我会转到不同的页面或者可能有一些动态内容)。 我也可以访问其他域名的代码。 所以我可以使用postMessage将iframe的源高度发送到我的页面。 但我似乎无法想象如何通过代码更改fancybox的高度。 我尝试设置包含iframe的所有div的高度,包括iframe本身: document.getElementById(‘fancybox-frame’).height = parseInt(height); document.getElementById(‘fancybox-content’).height = parseInt(height); document.getElementById(‘fancybox-outer’).height = parseInt(height); document.getElementById(‘fancybox-wrap’).height = parseInt(height); 我知道我正在通过所有权利,因为它完全适用于直接集成的iframe。 有人有任何想法吗? 谢谢 编辑:我也试过$ .fancybox.update(),但我不确定如何实现: $.fancybox({ ‘height’: height }); $.fancybox.update();

如何为iFrame按钮单击调用window onunload事件,父页面和iFrame位于不同的域中

我有一个打开iFrame的按钮(位于域中的’xyz’) ,iFrame加载了另一个域中的页面(比如’lmn’) $(“#templateSelectionFrame”).get(0).contentWindow.location.href = url; url来自另一个域(我在不同的域中使用Jquery’POSTMESSAGE’进行通信) 当用户从iFrame点击取消按钮时,我需要关闭iFrame,但在此之前需要显示页面留言(即留在页面/离开页面 – 这是在window.onbeforeunload调用的)。 var warnNavigateAway = true; window.onbeforeunload = confirmBrowseAway; // Called then user leave window without saving content. function confirmBrowseAway() { if (warnNavigateAway) { return “If you leave this page, your work will be lost …”; } } function documentSaved() { warnNavigateAway = false; } function documentDirty() { […]

使用jQuery postMessage插件的iframe跨域消息传递

我正在尝试使用以下插件在子iframe与其父级之间进行通信: http://benalman.com/projects/jquery-postmessage-plugin/ 我可以按照示例将一条消息从孩子发布到父母而不是其他方式,我真的需要能够以两种方式进行交流。 父代码如下: var origin = document.location.protocol + ‘//’ + document.location.host, src = origin + ‘/Custom/Ui/Baseline/html/iframe-data-cash.htm#’ + encodeURIComponent(document.location.href); $(function () { var $holder = $(‘#iframe’), height, $iframe = $(”); // append iframe to DOM $holder.append($iframe); }); $(window).load(function () { $.postMessage( ‘hello world’, src, parent.document.getElementById(‘data-cash-iframe’).contentWindow ); }); 孩子的代码如下: $(function () { var parentURL = decodeURIComponent(document.location.hash.replace(/^#/, […]

Uncaught SyntaxError:无法在’Window’上执行’postMessage’:调用’postMessage’时无效的目标原点’my_page’

我有以下脚本 父页面(pair_pixel_filter.php): window.addEventListener(“message”, function(e) { $(‘#log’).append(“Received message: ” + (e.data)); }, false); $(‘.photo-upload-btn’).click(function(event) { event.preventDefault(); window.open($(this).attr(“href”), “popupWindow”, “width=600,height=600,scrollbars=yes”); }); 儿童页面 $.ajax({ type: ‘post’, url: url, data: { base64data: dataURL }, success: function(data) { window.opener.postMessage(data, “pair_pixel_filter.php”); window.close(); } }); 基本上打开一个Popup,然后弹出一些ajax并将结果返回给父级。 但是从Child我得到了这个错误。 未捕获的SyntaxError:无法在’Window’上执行’postMessage’:调用’postMessage’时无效的目标原点’pair_pixel_filter.php’