如何检测iframe调整大小? [英] How do I detect iframe resize?

查看:136
本文介绍了如何检测iframe调整大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法检测我的iframe内容是否已更改?

Is there a way to detect if content of my iframe has changed?

我的解决方法是我有一个循环,不断检查其有效内容的高度但效率不高还有其他方法吗?

My workaround is I have a loop which constantly check for the height of the content it effective but not efficient is there another way of doing this?

推荐答案

由于iframe的内容有一个单独的 window 元素,您可以在iframe内的脚本中执行此操作。

Since the contents of the iframe has a separate window element, you can do this in a script inside of the iframe.

$(window).resize(function(){
  var object = $(this)
  // Use `object.height()` and `object.width()`.
});

您还可以使用 $(#the_iframe)[0]。 contentWindow.window (或类似的东西)而不是窗口来访问窗口对象来自包含iframe的范围的iframe。

You could also use $("#the_iframe")[0].contentWindow.window (or something like that) instead of window to access the window object of the iframe from the scope that contains the iframe.

这篇关于如何检测iframe调整大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆