iframe点击功能中的按钮会更改该父iframe的高度(跨域)

时间:2017-03-31 05:35:29

标签: javascript jquery html css

单击将高度更改为500px;

<iframe src="test.html" frameborder="0" scrolling="no" id="myIframe" class="chat-box width-350" style="height:300px;"></iframe>

iframe height设置为300px


的test.html

<a href="javascript:void(0)" class="clickhere">button</a>

点击“clickhere”时,iframe的高度会发生变化。

2 个答案:

答案 0 :(得分:0)

JQuery:

$('.clickhere').click(function() {
 $('#myIframe').css("height","500px");
}

答案 1 :(得分:0)

试试这个

for test.html

<a href="javascript:void(0)" class="clickhere">button</a>
<script type="text/javascript">
var parentIframe = window.parent.document.getElementById('myIframe');
var clickButton = document.getElementsByClassName('clickhere')[0];

clickButton.addEventListener("click", function(){
  parentIframe.style.height = '500px';
  console.log(parentIframe);
});
</script>