您的位置:首页 > 其它

记录一下最近做的项目的一些心得

2016-05-11 09:49 274 查看

一、首先是一个web项目

1、不要用iframe,不要用iframe,不要用iframe(重要的事情说三遍)

缺点1:iframe的高度问题,一般情况下用iframe是,同一个iframe里面会套入不同的几个页面,而这几个页面的高度不一定都会相同,那么你说你会把ifame的高度设多少,设置成最高的,页面矮的下面会有大片空白,设置成矮的高度,高的页面会显示不全,况且每个页面有可能因为数据量的不同高度也不一样。

解决方案1

function setIframeHeight(iframeId) {


var iframe = document.getElementById(iframeId);


if (iframe) {


var iframeWin = iframe.contentWindow || iframe.contentDocument.parentWindow;


var isChrome = navigator.userAgent.toLowerCase().match(/chrome/) != null;


if (iframeWin.document.body&&isChrome==true) {


iframe.height = iframeWin.document.documentElement.scrollHeight || iframeWin.document.body.scrollHeight;


}else{


if (iframe.contentDocument){//ff


iframe.height = iframe.contentDocument.body.scrollHeight;


if(isSafari=navigator.userAgent.indexOf("Safari")>0) {


//alert("Safari");


iframe.height = iframe.contentWindow.document.documentElement.scrollHeight;


}


//alert("1:"+Iframe.contentWindow.document.documentElement.scrollHeight);


}


else if(iframe.document && iframe.document.body.scrollHeight){//ie


iframe.height = iframe.document.body.scrollHeight;


//alert("2:"+Iframe.height);


}


}


}


};


此函数写在父页面里,传入iframeId进去,在子页面加载完成后调用
parent.setIframeHeight("iframeId");
来设置存放当前页面的iframe的高度。

缺点2:页面的加载速度问题,你知道吗,被iframe存放的页面要等其父页面全部加载完之后才会加载里面的页面,如果你的父页面加载的稍微慢点(如果父页面数据量小,没怎么跟服务器交互,请忽略此点。)。里面的子页面的数据量又比较大,那么iframe里面的页面会明显慢了好多,这给用户的体验是很不好的。

解决方案:用
<include></include>
代替,或者把你觉得慢的界面(子页面数据量多的页面)单独拎出来,要么就减少父页面的数据量和跟服务器的交互。自己可以权衡下。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: