搜索
系统检测到您的用户名不符合规范:

自动设置iframe高度,实现iframe高度自适应

浏览:2574 发布日期:2013年12月16日 分类:功能实现
自动设置iframe高度,供第三方调用,实现iframe高度自适应;
这个可以解决跨域问题。
iframe 如下<iframe id="showFrame" src="{:C('AuditResource')}" width="100%" height="620" border="0" frameborder="0"></iframe>iframe 的src地址包含如下代码片段:<iframe width="0" height="0" style="display: none;" src="http://domain/setIframeHeight?#300" name="iframeA" id="iframeA"></iframe>
<script type="text/javascript">
try {
function sethash() {
var hashH = document.documentElement.scrollHeight;
var urlC = "http://domain/setheight.html";
document.getElementById("iframeA").src = urlC + "#" + hashH + "#" + Math.random();
}
} catch (e) { }
</script>
http://domain/setiframeHeight 的代码如下: /**
*自动设置iframe高度,供第三方调用,实现iframe高度自适应
*/
public function setIframeHeight() {
header("Content-type: text/html; charset=utf-8");
echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
echo '<script type="text/javascript">
var b_iframe = parent.parent.document.getElementById("showFrame");
//var app_show_left = parent.parent.document.getElementById("aside_left");
var hash_url = window.location.hash;
var hash_width = hash_url.split("#")[1].split("|")[0];
var hash_height = hash_url.split("#")[1].split("|")[1];
if(undefined==hash_height) {
hash_height = hash_width;
hash_width = 0;
}
//b_iframe.style.width = hash_width;
b_iframe.style.height = hash_height+"px";
</script>';
}
收藏
leeyi
积分:4217 等级:LV4
热点推荐
(追記) (追記ここまで)
最新更新

我们

合作

网站

信息

ThinkPHP 是一个免费开源的,快速、简单的面向对象的 轻量级PHP开发框架 ,创立于2006年初,遵循Apache2开源协议发布,是为了敏捷WEB应用开发和简化企业应用开发而诞生的。ThinkPHP从诞生以来一直秉承简洁实用的设计原则,在保持出色的性能和至简的代码的同时,也注重易用性。并且拥有众多的原创功能和特性,在社区团队的积极参与下,在易用性、扩展性和性能方面不断优化和改进,已经成长为国内最领先和最具影响力的WEB应用开发框架,众多的典型案例确保可以稳定用于商业以及门户级的开发。

AltStyle によって変換されたページ (->オリジナル) /