使用JavaScript来适应跨域iFrame的高度

时间:2022-08-23 10:20:23

I have a rather tricky problem. I work with a client who are restricted to only use HTML, CSS and JavaScript. We have build a form using PHP and Javascript - and currently we only find it possible to embed the form using an iFrame. We have no FTP-access, so the iFrame is loaded from a different domain.

我有一个相当棘手的问题。我与仅限使用HTML,CSS和JavaScript的客户合作。我们使用PHP和Javascript构建了一个表单 - 目前我们只能使用iFrame嵌入表单。我们没有FTP访问权限,因此iFrame是从其他域加载的。

While the form use JavaScript to load new questions and results, this makes it difficult for the height to fit the screen. If the frame fits some of the screens, it will cut off some elements on other screens. While I am unable to upload any files to the FTP that contains the iFrame, it is not possible to use the helper-file solution, as described here.

虽然表单使用JavaScript来加载新的问题和结果,但这使得高度很难适合屏幕。如果框架适合某些屏幕,它将切断其他屏幕上的一些元素。虽然我无法将任何文件上传到包含iFrame的FTP,但是无法使用帮助文件解决方案,如此处所述。

So, my question is: is it possible to add a JavaScript action that change the css of the iFrame height, when a specific div id is loaded / action executed?

所以,我的问题是:当加载特定的div id /执行动作时,是否可以添加一个更改iFrame高度的css的JavaScript动作?

Thanks in advance! :)

提前致谢! :)

EDIT: I decided to solve this differently. But in case anyone else will stumble across this post, I think the solution offered here might work (if the code is updated to fit the latest jQuery). The main problem in my case seemed to be the limited access to the client domain.

编辑:我决定以不同的方式解决这个问题。但是如果其他人偶然发现这篇文章,我认为这里提供的解决方案可能有效(如果代码更新以适应最新的jQuery)。在我的情况下,主要问题似乎是对客户端域的有限访问。

1 个解决方案

#1


0  

You can't control the parent window document property if the iframe is from different domain. How ever you can try busting out of the iframe.

如果iframe来自不同的域,则无法控制父窗口文档属性。你怎么能尝试淘汰iframe。

https://css-tricks.com/snippets/javascript/break-out-of-iframe/

#1


0  

You can't control the parent window document property if the iframe is from different domain. How ever you can try busting out of the iframe.

如果iframe来自不同的域,则无法控制父窗口文档属性。你怎么能尝试淘汰iframe。

https://css-tricks.com/snippets/javascript/break-out-of-iframe/