• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

使用postMessage的跨域iframe调整大小

用户头像
it1352
帮助1

问题说明

我已经阅读了所有跨域iframe帖子(在此感谢所有人!)和其他地方.

I've read all the cross domain iframe posts here (my thanks to all of you!) and elsewhere.

跨域iframe调整程序中的postMessage脚本可以在以下环境中很好地工作:Firefox 5及更高版本.每次在iframe中完美点击页面时,它都会调整iframe的大小.

The postMessage script at cross-domain iframe resizer? works beautifully in Firefox 5 and up. It resizes the iframe every time a page is clicked within the iframe perfectly.

但是在计算机上的IE(7 8或9)中根本无法调整大小.我检查了安全设置,并选中了IE中的跨域访问设置,以启用该功能.

But it doesn't resize at all in IE (7 8 or 9) on my computer. I checked the security settings and the one in IE for access across domains was checked to enable.

postMessage在IE中不起作用吗?-还是需要添加其他内容?谢谢

Does postMessage not work in IE? - Or is there something else that needs to be added? thanks

正确答案

#1

这是thomax编写的出色脚本-它也可以使用,因此您可以在移动设备上使用iframe-iPhone和android

It's a great script from thomax - it also works on so you can use iframes on mobile - iphones and android

对于IE7和IE8,您必须使用window.attachEvent而不是window.addEventListenerps也应该是onmessage而不是消息(请参阅下文)ps,您还需要在服务器上执行同样的操作,内容要发布其大小

For IE7 and IE8, you have to use window.attachEvent instead of window.addEventListener It should also be onmessage instead of message (see below) ps you also need to do the same on the server with the content posting its size

<script type="text/javascript">
if (window.addEventListener)
{
  function resizeCrossDomainIframe(id) {
    var iframe = document.getElementById(id);
    window.addEventListener('message', function(event) {
      var height = parseInt(event.data)   32; 
      iframe.height = height   "px";
    }, false);
  }
}
else if (window.attachEvent)
{
  function resizeCrossDomainIframe(id) {
    var iframe = document.getElementById(id);
    window.attachEvent('onmessage', function(event) {
      var height = parseInt(event.data)   32; 
      iframe.height = height   "px";
    }, false);
  }
}
</script>

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhcfhike
系列文章
更多 icon
同类精品
更多 icon
继续加载