在IFrame中对jsp的onload是将IFrame设置为整个页面/浏览器



我在div中有一个IFrame,其SRC属性由JS函数动态设置。因此,如果src="file.jsp",那么一个包含对file.jsp中某些样式的调整的onload函数(位于file.jsp的主体内)在使用onload触发的函数后,会将IFrame悬停在整个网页上。即iframe正在整个网页上传播。请让我知道在onload函数之后需要做什么来保持IFrame的位置。

我的onload函数中的代码如所示

function load() {
    var url = window.location.href;
    if (url.indexOf('iip') > -1) {
        document.getElementById('peLibraryTreeDiv').style.width = "596px";
        parent.document.getElementById('privateEquityDiv').style.width =
                "96.9%";
        parent.document.getElementById('privateEquityDiv').style.top =
                "77px";
    }
}

这是一个非常有效且有效的示例

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <script>
        function changeIframe(newLocation){
            document.getElementById("myIframe").src=newLocation;
        }
        </script>
    </head>
    <body onload="changeIframe('http://www.example.com')">
        <div style="width:650px;float:auto;border:1px dotted #cccccc;">
            <iframe id="myIframe" src="http://www.ebay.co.uk/" width="100%" height=750px marginwidth=0 marginheight=0 hspace=0 vspace=0 frameborder=1 scrolling=auto>
              <p>Your browser does not support iframes.</p>
            </iframe>
        </div>
    </body>
</html>

请注意,有些网站不能作为src添加到iframe中,如http://www.google.com(不知道为什么,我在SO上提出了一个问题,这里不能将google.com作为src添加到IFrame中)

最新更新