获取iframe中的内容的高度,同时iframe中托管的外部网站,其code不能被访问 [英] Getting iframe content's height while iframe is hosting an EXTERNAL website whose code CAN'T be accessed

查看:167
本文介绍了获取iframe中的内容的高度,同时iframe中托管的外部网站,其code不能被访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  适合IFRAME对其内容的高度

由于在问题的标题描述。我正在寻找一种方式,根据我的IFRAME承载网站的高度来调整我的iframe的高度。因为我需要摆脱我的iframe的垂直滚动的。而在同一时间,我不希望设置一个非常巨大的静态高度我的iframe,因为这是不是很好,当我有小高地的页面。

As is described in the title of the question. I'm looking for a way to adjust the height of my iframe according to the height of the website that my iframe is hosting. Because I need to get rid of the vertical scroll of my iframe. And at the same time, I don't want to set a very huge static height to my iframe, as this is not nice when I have pages with small heights.

我发现有关我的问题很多解决方案,但解决不了我的问题:

I've found many solutions related to my problem, but can't solve my problem:

(*)更改iframe的高度,同时iframe中托管的内部网页很容易。你只需要添加下面的脚本到iframe onload事件:

(*) Changing the iframe's height while iframe is hosting an internal page is easy. You just add the following script to your iframe onload event:

        var frame = (document.getElementById) ? document.getElementById("YourFrameID") : document.all["YourFrameID"];
        var pageh = document.frames("YourFrameID").document.body.scrollHeight;
        frame.style.height = pageh + 'px';

但你会知道,当的src iframe的是具有iframe的外域。脚本崩溃并产生拒绝访问错误消息。

But as would you know, when the src of the iframe is outside the domain that has the iframe. the script crashes, and produces 'Access denied' error message.

(*)最后,我知道,如果我有机会到我的IFRAME承载的网页我的目标就可以实现。也许技术被称为跨域通信。

(*) Finally, I know that my goal can be achieved if I have access to the pages that my iframe is hosting. Perhaps the technique is called "Cross-Domain Communication".

不过,我的iframe的目标是接待来自外部网站的网页,并有向这些网站的访问权限。

HOWEVER, my iframe is aiming to host pages from EXTERNAL websites, and there is NO access to those websites.

这个问题已经被问了很多次。让我们通过提供一个最终的答案摆脱这个问题的:)

This question has been asked many times. Let's get rid of this issue by providing one final answer :)

或..让我们说,实现我的特定目标是不适用的。

Or.. let's say that achieving my specific goal is not applicable.

请注意,我用ASP.NET 4.0

Note that I use ASP.NET 4.0

谢谢,

推荐答案

这是根本不可能的,由于跨域安全方面的原因。

It is simply not possible due to the cross domain security reasons.

这篇关于获取iframe中的内容的高度,同时iframe中托管的外部网站,其code不能被访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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