0

I have an IFrame in a DIV with its SRC attribute being dynamically set by a JS function. So, if src="file.jsp", then an onload function(inside the body in file.jsp) that contains adjustments to some styles inside the file.jsp was hovering IFrame all over the webpage once it was done with the function triggered by onload. i.e., iframe is spreading all over the webpage. Please let me know what needs to be done to preserve the IFrame position after the onload function.

The Code in my onload function is as shown

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";
    }
}
Ryan Kohn
  • 13,079
  • 14
  • 56
  • 81
  • can you please rephrase because it is not clear what you are trying to achieve... – MaVRoSCy Aug 27 '12 at 07:38
  • I mean adding any type of content in onload() method of a file.jsp(this appears in an Iframe in a DIV) is leading to display the iframe itself entirely in the browser. – user993195 Aug 27 '12 at 10:57
  • can you show the onload function and the html code of your div and the css of your div? – MaVRoSCy Aug 27 '12 at 11:19

1 Answers1

0

this is a perfectly valid and working example

<!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>

please note that some websites cannot be added as src to an iframe like http://www.google.com (not sure why, I have made a question on SO here can't add google.com as src to an IFrame)

Community
  • 1
  • 1
MaVRoSCy
  • 17,747
  • 15
  • 82
  • 125