自动高度IFrame [英] AutoHeight IFrame

查看:97
本文介绍了自动高度IFrame的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想制作一个iframe页面,以便从其他页面加载页面 地点.我已经尝试过"jQuery iFrame Sizing"来设置自动高度 iframe ...但是失败了.

i want to make a iframe page that loading a page from other site. I have try "jQuery iFrame Sizing" to set auto height in iframe... but it is failed.

出什么问题了??

这是我的代码:

on Head:
<script type="text/javascript" src="js/jquery.js" ></ script >
<script type="text/javascript" src="js/iframe.js"></script >

on Body:
<iframe scrolling="no" frameborder="0" width="1025" src="http://mydomain.com"/>
</iframe>

推荐答案

是的,由于浏览器的安全性限制,Javascript无法访问从另一个域加载的iframe源.但是,有一种解决方法,不是很理想,但是可以解决.

Yes, due to browsers security limitations Javascript doesn't have the access to iframe's source that is loaded from a another domain. However there is a workaround for that, not ideal, but it works.

您可以使用简单的本地脚本胜过"浏览器,该脚本将加载和输出mydomain.com的内容.然后将iframe src指向此脚本.在这种情况下,浏览器会认为您正在处理相同的域,并且限制将不适用.

You can "outsmart" the browser using a simple local script that will load and output contents of mydomain.com. Then point the iframe src to this script. In that case browser will think you're dealing with the same domain and limitations won't apply.

所以代替这个:

<iframe scrolling="no" frameborder="0" width="1025" src="http://mydomain.com" />

您可以尝试如下操作:

<iframe scrolling="no" frameborder="0" width="1025" src="/local-script.php?url=http%3A%2F%2Fmydomain.com" />

然后,您可以在local-script.php中添加一个简单的逻辑,以加载所需的域/文档的内容,一切都应该很好. LMK,如果您需要一个PHP脚本示例.

Then you can add a simple logic into local-script.php that loads contents of domain/document you want and everything should be fine. LMK, if you need an example of PHP script.

这篇关于自动高度IFrame的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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