[英]iframe resize cross domain no control
I have read several articles and tried some methods, but no results. 我已经阅读了几篇文章并尝试了一些方法,但没有结果。 What I need to do is resize the height of iframe tag on the parent dynamically. 我需要做的是动态调整父级iframe标记的高度。 I can't modify the page I put on the iframe src, as it is an application on the intranet in another server. 我无法修改我放在iframe src上的页面,因为它是另一台服务器内部网上的应用程序。
I know there are security issues, but I need this functionality on the page, as the app should show seamless on the intranet webpage. 我知道存在安全问题,但我需要在页面上使用此功能,因为应用程序应在Intranet网页上无缝显示。 I would like to see options, methods or workarounds to achieve this. 我想看看实现这一目标的选项,方法或解决方法。
I also tried to resize the iframe based on the scroball, but no luck. 我也试图根据scroball调整iframe的大小,但没有运气。
Anyone can help me. 任何人都可以帮助我。
The parent: 父母:
http://jsbin.com/ujAqemI/1/edit http://jsbin.com/ujAqemI/1/edit
function handleMessage(e) {
if (e.data.action == 'resize') {
var targetHeight = e.data.height;
$('#iFrame').animate({
height: targetHeight
});
}
}
window.addEventListener("message", handleMessage, false);
The iframe: iframe:
http://jsbin.com/azUWIye/1/edit http://jsbin.com/azUWIye/1/edit
parent.postMessage({
'action':'resize',
'height': 400
}, '*');
You can change the height attribute using jQuery easily enough. 您可以使用jQuery轻松更改height属性。 code: 码:
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
<script>
function ChangeIframeHeight()
{
$('#iframename').attr('height', "900") //Changes the "height" attribute to 900
}
<body>
<iframe src = "http://google.com" height = "600" width = "900"></iframe>
</body>
</html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.