使用postMessage的跨域iframe调整大小
问题说明
我已经阅读了所有跨域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
正确答案
这是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
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
检查邮件是否发送成功
it1352 07-25 -
Android微调工具-删除当前选择
it1352 06-20 -
希伯来语的空格句子标记化错误
it1352 06-22 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20