【发布时间】:2017-07-14 18:57:07
【问题描述】:
这是我的 iframe,它位于带有按钮的 div 中
function myFunction() {
var url =document.getElementById("myFrame").getAttribute("src");
var newUrl = url.substring(0,url.indexOf("width")) + "width=320&height=270";
document.getElementById("myFrame").setAttribute("src",newUrl);
document.getElementById("myFrame").setAttribute("style","border:none;overflow:hidden;width:320px;height:270px;");
}
<div style="width:auto;height:auto;" id="mydiv">
<iframe id="myFrame" src="http://domain.com/page.php?width=400&height=400" height="400" width="400"></iframe>
</div>
<button onclick="myFunction()">Change Size</button>
我需要的是我的代码可以改变 iframe 的大小,并且它的 src 链接是大小。但如您所见,我的 id 为“mydiv”的 div 的样式宽度和高度是自动的。当我使窗口更大时,我需要我的代码在宽度和高度上保持 100% 全宽,div 是尺寸增加,但 iframe 不会改变,因为它具有固定大小。
我试过了
("style","border:none;overflow:hidden;width:100%;height:100%;")
("width")) + "width=100%&height=100%"
但它不能正常工作。任何一个 iframe 都搞砸了,但不能正常工作。希望您理解我在这方面确实需要帮助。
【问题讨论】:
标签: javascript jquery html css iframe