I have an iframe in aspx page:
<iframe style="width: 100%;" src="" scrolling="auto" id="reportFrame" runat="server">
</iframe>
And JavaScript I am using is below”
<script type="text/javascript">
function getElement(aID) {
return (document.getElementById) ? document.getElementById(aID) : document.all[aID];
}
function getIFrameDocument(aID) {
var rv = null;
var frame = getElement(aID);
// if contentDocument exists, W3C compliant(e.g.Mozilla)
if (frame.contentDocument)
rv = frame.contentDocument;
else // bad Internet Explorer ;)
rv = document.frames[aID].document;
return rv;
}
function adjustMyFrameHeight() {
var frame = getElement("reportFrame");
var frameDoc = getIFrameDocument("reportFrame");
alert(frameDoc);
frame.height = frameDoc.body.offsetHeight + 15;
}
</script>
But I have a case for the src in my .cs page as we retrieve src from query string so the code is:
case "Case1":
reportFrame.Attributes["src"] = "acd.aspx";
reportFrame.Attributes["height"] = "355px"; //giving iframe height as script now working.
In page load:
this.reportFrame.Attributes.Add("onload", "adjustMyFrameHeight();");
I have specified the script in the page load as well as since we are using runat=”server” but still script is now working.
Any help?
I just got an answer after debugging the script step by step that in order to get the Id of the frame, I must specify the whole or complete Id as it was inherited in a Content placeholder of the Master page so whole Id had to be given.