
1js控制iframe
<div id="dd">132</div>
<script>
var s = '<iframe src="javascript:documentopen();documentwrite(\'<script>alert(1);<\/script><div>test</div>\');documentclose();"></iframe>';
documentgetElementById("dd")innerHTML = s
</script>
<iframe id="tst" name="tst" ></iframe>
<script>
alert(2);
var cw = windowdocumentgetElementById('tst')contentWindow;
cwdocumentopen();
cwdocumentwrite('<script>alert("test")<' + '/script>');
cwdocumentwrite('<div>test</div>');
cwdocumentclose();
</script>
IE6,IE7,FF2下测试通过
在id为"ifr"的iframe内容里写上js代码:
<script>
function resize(){
parentdocumentgetElementById('ifr')styleheight = documentbodyscrollHeight>300documentbodyscrollHeight:300+"px";
}
windowonload=resize;
windowonresize = resize;
</script>
就能控制id为"ifr"高度至少为300px
要是回答的内容有问题,或认为不妥,请发送百度消息给我,消息内容加上本页网址哦。。
·
你用jq的时候是在页面加载的时候就获取了,并不是点击的时候获取的。时机不对。
$('#btn2')click(function () {var boxAheight = $("#frame_content")outerHeight(true);
alert(boxAheight);
})
<script type="text/javascript">
function setHeight(){
var iframe = documentgetElementById("iframe_id");
try{
var aHeight = iframecontentWindowdocumentbodyscrollHeight;
var bHeight = iframecontentWindowdocumentdocumentElementscrollHeight;
var height = Mathmax(aHeight, bHeight);//取最高值;
iframeheight = height;
}catch (e){}
}
</script>
在iframe中把height="XXX"不要 加入onload="setHeight()"
1、在文件夹里创建两个html文件,一个“index”一个“iframe”。
2、在index中添加一个iframe标签,直接嵌入iframe页面。
3、在iframe网页中添加了两个固定高度的div内容。
4、浏览器打开index页面我们发现iframe部分有滚动条,需要滚动显示页面。
5、现在我们在index页面的iframe标签再添加如下的属性。
6、再次打开index页面iframe已经高度自适应了。
以上就是关于js写入的iframe自适应高度问题(急)全部的内容,包括:js写入的iframe自适应高度问题(急)、jq怎么获取自适应高度的iframe高度的准确数值、JS怎么控制IFRAME高度自动适应内容而不出现滚动条等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)