Javascript iFrame高度使用jQuery进行调整
我想根据其中的内容自动调整iframe的高度。我用jQuery插件jQuery iframe auto height by house9完成了这项工作,它运行得非常好 现在我希望我的主页(在iframe中)具有父页面的完整高度。我想我应该使用if-else语句,但由于我还没有javascript方面的经验,我希望你们中的一位能够帮助我Javascript iFrame高度使用jQuery进行调整,javascript,jquery,iframe,height,Javascript,Jquery,Iframe,Height,我想根据其中的内容自动调整iframe的高度。我用jQuery插件jQuery iframe auto height by house9完成了这项工作,它运行得非常好 现在我希望我的主页(在iframe中)具有父页面的完整高度。我想我应该使用if-else语句,但由于我还没有javascript方面的经验,我希望你们中的一位能够帮助我 $(document).ready(function () { if ((#ifrm).($this).attr('src') == 'home.html
$(document).ready(function () {
if ((#ifrm).($this).attr('src') == 'home.html'){
$('#ifrm').iframeAutoHeight({minHeight: 100%});
}
else $('#ifrm').iframeAutoHeight({minHeight: 300});
});
我还发现了一个获取页面完整高度的代码,也许它有帮助
if ($('#ifrm').($this).attr('src') == 'home.html'){
(function(){var height = $(window).height();
$('#ifrm').css('height', height)
});
}
else $('#ifrm').iframeAutoHeight({minHeight: 300, debug: true});
事先非常感谢
编辑:您可以找到此代码用于的网站此代码适用于您:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
if ($('#ifrm').attr('src') == 'home.html') {
var window_height = $(window).height();
$('#ifrm').css("height", window_height);
}else{
$('#ifrm').load(function() {
this.style.height =
this.contentWindow.document.body.offsetHeight + 'px';
});
}
});
</script>
<iframe src="home.html" id="ifrm">
$(文档).ready(函数(){
if($('ifrm').attr('src')=='home.html'){
var window_height=$(window.height();
$('ifrm').css(“高度”,窗口高度);
}否则{
$('#ifrm').load(函数(){
这是我的风格=
this.contentWindow.document.body.offsetHeight+'px';
});
}
});
它不仅可以在不使用插件的情况下自动调整iframe的高度,还可以设置“home.html”页面的完整高度
请记住,只有当iframe内容在同一个域上时,这才有效,来自其他域的iframe的内容出于安全考虑被锁定。我认为您的意思是
if($('ifrm').attr('src')=='home.html')){
非常感谢您!如果您想查看它是用于哪个站点的,。在完成此站点之前,这是我必须做的一件大事,因此这是一个很大的解脱。:)