开发者

Fancybox / iFrame location (cross domain) using postMessage

I am trying to grab the location of an iFrame (开发者_运维问答in a fancybox) when the user clicks a button in the title area. It's on a different domain so I'm using postMessage, and I want it to grab the full url (eg "www.example.com?pid=12345") so when the fancybox is closed using the "Attempt Search" button, my site can then search for the pid "12345".

Snippets...

<script type="text/javascript">
  window.addEventListener("message", function(e) {
    alert(e.data + " : " + e.origin + " : " + e.source);
  }, false);
</script>


<script type="text/javascript">
  $(document).ready(function() {
    $("a#codelookup").fancybox({
    'width' : 1050,
    'height' : '75%',
    'title' : '<p class="wrapbutton"><a href="javascript:;" onClick="postMessage(\'Hello?\', \'*\'); $.fancybox.close();">Attempt Search</a></p>',
    'titlePosition' : 'inside',
    'type' : 'iframe'
  });
});

This alerts the "Hello?" message OK, but e.origin returns the parent domain (not the iFrame's url). And if I postMessage(this.location, '*') it's undefined.

Can anybody help please?


It is not possible. For security reasons, an iframe of a different domain can not communicate with the page that it is being framed in on.


Have you tried this library? http://easyxdm.net/wp/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜