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

时间:2012-08-27 07:34:54

标签: javascript

我在DIV中有一个IFrame,其SRC属性由JS函数动态设置。所以,如果src =“file.jsp”,那么包含对file.jsp中某些样式的调整的onload函数(在file.jsp中的body内部)一旦完成了触发的函数就在整个网页上悬停IFrame通过onload。即,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";
    }
}

1 个答案:

答案 0 :(得分:0)

这是一个完全有效且有效的例子

<!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添加到像http://www.google.com这样的iframe(不知道为什么,我在这里提出了问题can't add google.com as src to an IFrame

相关问题